# Given three vectors, determine if one is in the middle

This topic is 4973 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015296
×