How can I work out if a point x,y,z is contained by a cone ?
January 14, 2007 5:33 PM
Subscribe
How can I work out if a point x,y,z is contained by a cone ?
I'm exploring some 3d programming, but sadly geometry is not my strong point.
I can define a cone object :
P1(x,y,z) - point of cone
P2(x,y,z) - centre of the base of cone
R1 - radius of the base.
How do I test if a point P3(x,y,z) is inside the surface of the cone ?
If it is inside the cone, how do I determine the closest point on the surface of the cone to P3 ?
I'd like to write a generic function so I can reuse it in other programming languages.
I'd prefer the cone base to be an elipse, I guess I could add a second raduis and rotation around the x-axis, but I'm out of my depth already.
I've looked through wikipedia and wolfram's but the crazy notation they use are all but meaningless to me.
Thanks
posted by matholio to computers & internet (15 comments total)
1 user marked this as a favorite
the trick is to move all 3 points (p1,p2,and the test point which i'll call tp) around and simplify the problem.
1) move them so that p1 is at the origin(0,0,0), i.e. subtract p1 from p2 and tp,
2) rotate the p1-p2 line so that it falls along an axis (x,y,or z) it doesnt matter which one, just pick one, and apply the same rotational transformations to tp.
3) then you can see if p3 at least falls within p1 and p2, a precondition for being in the cone
4) if it does fall in that region, then measure the distance of tp to the axis that p1 and p2 lie along
5) so if it's closer to the axis than the radius of teh cone would be at that point of the axis
posted by garethspor at 5:49 PM on January 14, 2007