Jump to content
  • Advertisement
Sign in to follow this  
thedigga007

Given three vectors, determine if one is in the middle

This topic is 4733 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

I have three objects which I can represent as 3, 3D vectors, vector1, vector2, and vector3. However for simplicity I only need to worry about the x and z plane so they are now 2d vectors. I need to check if vector2 is between vector1 and vector3 where vector3 is behind vector2 and facing the same direction and vector1 is in front of vector2 and facing the oppositie direction (facing vector2). How can I calculate this (fast)? I was thinking using a 2D dot product to determine the angle between but I think that will only work for the vector behind vector2. Hope this is clear. -Digga

Share this post


Link to post
Share on other sites
Advertisement
When you want to test in-front and behind, then you have a half-space problem. Half-spaces are represented as dividing planes, where a dot product with the normal and a compare with the constant will tell you which side of the plane you're on.

Thus, figure out how to construct the plane that answers the question you're asking, construct that plane from the input data, and test the vector.

If your answer area is actually not shaped like a plane, then it's probably a wedge of some number of limiting planes, and you can just figure out the planes needed and test them all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!