• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Cylinder intersection

This topic is 5754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I would like to find the intersection of a line defined by p(t) = O + t * D (O is a point on the line and D is its direction vector) with a cylinder from p1 to p2 with a radius r (not the usual cylinder: radius, position, height). I need this because I would like to make a cylinder enveloppe around bone parts of a model for ray collision detection. I had a look a this site but I could not understand the math notation : http://mrl.nyu.edu/~dzorin/rendering/lectures/lecture3/lecture3-6pp.pdf [edited by - Shnoutz on April 20, 2003 3:07:21 PM]

##### Share on other sites
What part of the notation do you have trouble with? Intersection formulas are usually the solution of two parametric expressions, with one being the ray and the other being the object. Do you have trouble with the parametric expression for a general cylinder, or do you have trouble with the solution of the two expressions?

##### Share on other sites
The equation of the general cylinder presented is :

(q - pa - (va, q - pa)va)^2 - r^2 = 0

- what is the meaning of "(va, q - pa)va" ?

- is "(q - pa - (va, q - pa)va)" scalar or vector ?

##### Share on other sites
Give this explanation a shot:
http://astronomy.swin.edu.au/~pbourke/geometry/lineline3d/

Comes from this site:
http://astronomy.swin.edu.au/~pbourke/geometry/

##### Share on other sites
I thought about using the shortest distance between a 2 lines but it is not the equivalent to a cylinder intersection...

##### Share on other sites
It almost is the shortest distance between two lines. But instead look at the solution from a different way. Don''t find the shortest distance, but find the two points on the axis where the perpendicular distance is the radius. Now you need to check if either that point on the axis falls within the cylinder, or if both points are either side.

I''ve just got up 3 hours earlier than usual, so my head''s not all that clear, but I think that covers all eventualities of intersection, except if they''re parallel of course, but that makes it really easy.

One thing to be careful of is to make sure you find the perpendicular distance from the axis and not the line.

##### Share on other sites
I did this not too long ago, but I don''t think it is worth the amount of CPU power to compute in anything time-constrained like a game, but here is the intersection of a cylinder(P1, P2) by a ray(P3, P4):

REFER TO THE PAUL BOURKE SITE FOR NOTATION USAGE
http://astronomy.swin.edu.au/~pbourke/geometry/lineline3d/

The concept is that any point on the ray that is exactly the cylinder''s radius away will be a point of intersection on the cylinder''s surface. We''re gonna express this using two equations which describe our conditions:
(Pb - Pa) dot (Pb - Pa) = radius^2
- AND -
(Pb - Pa) dot (P2 - P1) = 0

Now I do an *ssload of algebra and reduction to end up with the following equation:
(mub^2)(d4343 - ((d4321^2)/d2121)) + mub(2*d4331 - 2((d3121*d4321)/d2121)) - (d3121^2)/d2121 + d3131 - radius^2 = 0
where
''mub'' is the parametric variable in the ray''s line equation:
Pb = mub(P4 - P3) + P3

This is a quadratic function and being such, you will be left with 4 possible outomes:
2 solutions: ray passes through the cylinder
1 solution: ray grazes the surface of the cylinder like a tangent
0 solutions: ray does not pass close enough to contact cylinder
undefined solution: ray is parallel to cylinder

You can also use ''mub'' to find where along the cylinder an intersection lies if any exist:
mua = (mub*d4321 + d3121)/d2121
where
''mua'' is the parametric variable in the cylinder''s line equation:
Pa = mua(P2 - P1) + P1

If the value of ''mua'' is between 0.0 and 1.0, then an intersection on the cylinder lies between points P1 and P2, respectively.

Any questions?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 12
• ### Forum Statistics

• Total Topics
634116
• Total Posts
3015598
×