Point Contained by Cone
by Nathan Kent · in Technical Issues · 08/09/2008 (3:02 pm) · 6 replies
This is a two part question:
1. Is there a generic formula for checking if a point is contained in a cone?
2. Would that formula be simple enough to call (in C++) once every tick?
Thanks in advance!
Edit-> Another question came up, so I figured I'd add it here:
3. What is the formula for the vector from a foci to the center of the ellipsoid? I know it for ellipses, but I'm not sure if that will apply to ellipsoids too.
1. Is there a generic formula for checking if a point is contained in a cone?
2. Would that formula be simple enough to call (in C++) once every tick?
Thanks in advance!
Edit-> Another question came up, so I figured I'd add it here:
3. What is the formula for the vector from a foci to the center of the ellipsoid? I know it for ellipses, but I'm not sure if that will apply to ellipsoids too.
About the author
#2
08/09/2008 (5:30 pm)
Thanks! Questions 1 and 2 answered!
#3
Well, if it is that, it depends on the type of ellipsoid you are working with. If its a spheroid, it will be the same as in the case of an ellipse.
08/09/2008 (6:12 pm)
As for qt 3, you mean the vector going from the focus of the ellipsoid to the center of the ellipsoid?Well, if it is that, it depends on the type of ellipsoid you are working with. If its a spheroid, it will be the same as in the case of an ellipse.
#4
08/09/2008 (6:27 pm)
It's a scalene ellipsoid. I think that it would be the same, but I have no good way to test that right now.
#5
For an ellipse, taking the geometric relationship between the foci i.e. the sum of distances of any point on the curve to each of the two foci is constant, and extending it to an ellipsoid will result in a spheroid, because the distance in the plane containing the focus, and normal to the line joining the center and the focus, from the corresponding focus of the projected ellipse, will remain the same for any point in this plane. The same would apply to the other focus as well.
I hope I'm a little clear. If not, maybe I could draw up a diagram or something.
PS: Just curious, are you trying to setup some collision stuff or something?
08/09/2008 (9:30 pm)
Forgive me, maybe I just forgot my math, but how do you define a focus for a scalene ellipsoid? It would form 3 elliptic projections on each of the co-ordinate planes, with two foci each.For an ellipse, taking the geometric relationship between the foci i.e. the sum of distances of any point on the curve to each of the two foci is constant, and extending it to an ellipsoid will result in a spheroid, because the distance in the plane containing the focus, and normal to the line joining the center and the focus, from the corresponding focus of the projected ellipse, will remain the same for any point in this plane. The same would apply to the other focus as well.
I hope I'm a little clear. If not, maybe I could draw up a diagram or something.
PS: Just curious, are you trying to setup some collision stuff or something?
#6
x = TargetX - EllipsoidsPosition, y = TargetY - EllipsoidsPosition, and z = TargetZ - EllipsoidsPosition (a, b, and c are defined in the AIPlayer's datablock).
08/10/2008 (3:21 am)
Quote:Doh! I was originally planning on using three ellipses, but I wound up using an ellipsoid since it would give me the same area. What I could do is get the vector using only the "horizontal" ellipse.
Forgive me, maybe I just forgot my math, but how do you define a focus for a scalene ellipsoid? It would form 3 elliptic projections on each of the co-ordinate planes, with two foci each.
Quote:It isn't you being unclear, it was me not being clear in my head or in my posts. I wrote foci and thought "foci of the ellipses in the ellipsoid who's foci are on the same line" and didn't realize that I had asked myself the answer. =P
I hope I'm a little clear. If not, maybe I could draw up a diagram or something.
Quote:Actually, I'm using this for AI vision, and an ellipsoid forms the area where objects have a 100% chance of being seen (if the are in the AI's LOS). The AIPlayer would be at one of the "foci" with the center of the ellipsoid in the direction of the eye vector.
PS: Just curious, are you trying to setup some collision stuff or something?
x = TargetX - EllipsoidsPosition, y = TargetY - EllipsoidsPosition, and z = TargetZ - EllipsoidsPosition (a, b, and c are defined in the AIPlayer's datablock).
(x^2/a^2) + (y^2/b^2) + (z^2/c^2) < 1If that returns true, than the object is in the ellipsoid and I can proceed to do raycasts, otherwise I do the same thing for the AIPlayer's "cones of vision". The only difference is that there is a chance that the AI won't see objects in the cones (80% to 30% chance they will).
Torque 3D Owner Morrock
Take the vector P2-P1 and the vector P3-P1. Normalize them both to unit length. Their dot product is then cos(angle P3-P1-P2). If this number is greater than or equal to the cosine of the half-angle at the apex of the cone, then the point is inside the cone. (If it's exactly equal, then P3 is on the cone.)
P1 = point of cone. P2 = center of cone base, P3 = point you are testing.
So in code something like:
Point3F vec1 = P2 - P1; Point3F vec2 = P3 - P1; vec1.normalize(); vec2.normalize(); F32 dot = mDot(vec1, vec2); if (dot >= (mCos(angle/2))) //angle is the angle of the cone return true; else return false;I don't think this takes into account distance however.