"Collision detection tutorial" - читать интересную книгу автора (Christopoulos Dimitrios)

Ray – Cylinder intersection

Computing the intersection between an infinite cylinder and a ray is much more complicated that is why I won't explain it here. There are way too many math involved too be useful and my goal is primarily to give you tools how to do it without getting into much detail (this is not a geometry class). If anyone is interested in the theory behind the intersection code, please look at the

Graphic Gems II Book (pp 35, intersection of a with a cylinder). A cylinder is represented as a ray, using a start and direction (here it represents the axis) vector and a radius (radius around the axis of the cylinder). The relevant function is

int TestIntersionCylinder(const Cylinderamp; cylinder, const TVectoramp; position, const TVectoramp; direction, doubleamp; lamda, TVectoramp; pNormal, TVectoramp; newposition)

Returns 1 if an intersection was found and 0 otherwise.

The parameters are the cylinder structure (look at the code explanation further down), the start, direction vectors of the ray. The values returned through the parameters are the distance, the normal at the intersection point and the intersection point itself.