Whats the preferred method of storing a "rotation segment/area/field/range" in 3D - not sure what to call them.

Started by
8 comments, last by haegarr 8 years, 9 months ago

What I want to do is to set a limit on the allowed direction/forward of an object in 3D. In 2D, that would be say a angle range [0-45] degrees and an object's angle is clamped to within those range. Now I want something equivalent in 3D. It is not quite a orientation as I dont care for Z roll. So I am wondering how this is usually done? Ideally, the said structure should allow for a test to check whether a quaternion or rotation matrix is within its specified range. Or if it easier, test whether the object's current direction/forward is within the specified range.

Advertisement

Use an axis and an angle, then check whether the proposed orientation dot axis is within the angle, it's a cone check, if both axes are normalised the dot product will be > cos(angle) if it is within the cone

EDIT: > not <

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
I would do the same thing Paradigm Shifter suggested, but I would word it differently: Use a direction and an angle to describe the cone to which the forward direction is constrained; then you can check if your forward vector is within the cone by checking if dot(forward, cone.direction) >= cos(angle), assuming both forward and cone.direction have length 1.

And if you need to clamp it you can just subtract a vector in direction from the end of the the orientation to the end of the cone axis until the cosine is equal, then renormalise, I believe.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

It should perhaps be mentioned that the dot-product method described above uses unsigned angles (i.e. it makes no distinction whether the angle grows clockwise or counter-clockwise when in 2D). From the OP, the example "range [0-45] degrees" can be understood as "at most 45° around the standard direction" which would mean the interval [-45°, 45°] for the signed angle. This would match the dot-product method, where the symmetry axis of the section (when in 2D) or cone (when in 3D) corresponds to the standard direction. The "range [0-45] degrees" could also be understood as signed angle interval by itself. In that case the dot-product can still be used when the symmetry axis is set to the center of the interval.

BTW: Of course, in 3D the possible variations of "range" are higher than in 2D. The cone could be an elliptical one, or a pyramid can be used instead.

And if you need to clamp it you can just subtract a vector in direction from the end of the the orientation to the end of the cone axis until the cosine is equal, then renormalise, I believe.


The straight-forward way to clamp is to first use orthogonal projection to express the forward vector as the sum of vectors v and w, where v is proportional to the central direction of the cone and w is perpendicular. Then move forward to be v*cos(angle)+w*sin(angle), using the "most natural" rotation.

EDIT: For completeness,
Vector v = dot(forward, cone.direction) * cone.direction;
Vector w = forward - v;

Cone. Of course. Funny I never thought of them as cones even though that is exactly what they are.

Now suppose if I want to use pyramids in addition to cones, then what I need to do is 4 vector-plane normal test to check whether or not the forward vector is inside the specified "range." What I am uncertain about is how to clamp the forward vector to inside the pyramid if it was outside?

If the dot product between forward vector and plane normal is negative, then I need to "rotate" the vector to be same "direction" as the plane (not sure on the correct mathematical term). Problem is how do I do this "rotation"?

If the dot product between forward vector and plane normal is negative, then I need to "rotate" the vector to be same "direction" as the plane (not sure on the correct mathematical term). Problem is how do I do this "rotation"?

Reflect it in the plane which is normal to the cone axis first then proceed as before. If you are already on that plane add some scaled amount of the cone direction to it.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Im afraid you lost me at cone axis. I was referring to use pyramid instead of cones in case I wasnt clear.


Now suppose if I want to use pyramids in addition to cones, then what I need to do is 4 vector-plane normal test to check whether or not the forward vector is inside the specified "range." What I am uncertain about is how to clamp the forward vector to inside the pyramid if it was outside?

Not necessarily. There is at least one other way (although I do not say that it is easier ;)): Using the pyramid can be understood as separation of the 3D problem into two 2D problems. Think of 2 orthogonal planes that intersect along the axis of the pyramid. Project the 3D vector in question onto the planes, and perform the 2D dot-product method for each projection. Then mix the components of the results to the constrained 3D vector.

This topic is closed to new replies.

Advertisement