PDA

View Full Version : Intersection of a line and a cone?



Robbo
03-01-2002, 08:28 AM
Hi, I'm using gluUnProject to generate a ray from the mouse cursor so that the user can just move the mouse over the scene and get `tool tip' on any given position.

Most of my scene objects are conical (defined in space as two radii and two vertices). I would like to know how to calculate the intersection of a ray\line and this cone so that I can then select the correct point to give tool-tip information about.

Looked on the web and no-joy. Any hints?

Zeno
03-01-2002, 10:21 AM
Always check Magic Software first when you need an algorithm to test for intersections:
http://www.magic-software.com/Source/Intersection3D/MgcIntr3DLinCone.cpp

-- Zeno

Robbo
03-01-2002, 12:39 PM
Yea - I checked that out but his definition of a cone, while probably correct, does not deal with conical shaped objects. My cones do not have a single vertex at the peak - they are just `cylinders' with one end radii less or more than the other.

Can't really see how to do this - I need to know the conical intersection point before i can determine which triangle it intersects with in the scene (don't want to test all triangles in some candidate area - that would be too much work!).

davepermen
03-01-2002, 12:57 PM
how about this:
cone uncapped = real_cone_without smaller_radius_but_up_till_the_point_of(cone);
cone cap = from_point_to_small_radius_of(cone);

if(intersects(uncapped)&&!intersects(cap)) printf("intersects(cone)");

jwatte
03-01-2002, 02:10 PM
Daveperman,

That won't work, as a ray (or sphere, or whatever) may easily intersect both the capped and the uncapped part. Think of anything intersecting the smaller of the two sliced-cone caps to figure out why.

Overmind
03-02-2002, 05:18 AM
You can define a real cone and cap it with a plane. Then you determine the TWO intersection points with the cone (the ray enters it and exits it on the other side).

If one of them is below the capping plane the capped cone is hit. You only have to deal with the special case that the ray goes through the base and top circle. For that just test if the ray intersects the plane within the radius.

Robbo
03-02-2002, 02:24 PM
Ok, but how? Gimme some code!

I'm not lazy, its just that I don't have time to figure it out for myself (product launch in six weeks!).

Thanks.!!!!

Gorg
03-02-2002, 02:48 PM
You have all the code you need. The rest is very easy.

From your capped coned, build a real cone in the direction of the smaller cap. ( you have to write this )
Easy : You need : Rsmall( radius of small cap) Rbig(radius of the big cap) D( distance from one cap to the other ), a (normalized axis of your cone ) and centerSmall( center of your small cap ). So
PointOfTipOfCone = centerSmall + a * ( d*Rsmall/Rbig )

Take majik software routine. ( you can take it )

If the ray intersects with the cone, check if the point is outside or inside the small cap plane. ( you have to write this )

If it does not intersect, do a simple ray-plane intersection for the 2 caps and check if the intersection point is in the radius. ( you have to write this )


That is what Overmind explained.




[This message has been edited by Gorg (edited 03-02-2002).]

Robbo
03-03-2002, 12:39 AM
Ok, I've got you now. Actually, it makes perfect sense http://www.opengl.org/discussion_boards/ubb/wink.gif


Thanks a lot for all your help here ppl.


[This message has been edited by Robbo (edited 03-03-2002).]