Jump to content
  • Advertisement

Archived

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

Shnoutz

Cylinder intersection

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!