Sign in to follow this  

Easiest way to use the Cross product to Determine what side of a point you are on...

Recommended Posts

So I have a point and I want to know if I am on the left or right side of the point. My way of figuring out what side of the point I am on would be like so

vecFromPointToPlayer = PlayerPos - Point
vecCross = cross(vecFromPointToPlayer, WorldUp)

At this point our vecCross is either pointing in front or behind us. So now I need to figure that out so

vecCrossToPlayer = PlayerPos - Cross
if(vecCrossToPlayer.x < 0)
//Ur on the left
//Ur on the right

That is probably not the best way to do it... do you guys have a better way?

Share this post

Link to post
Share on other sites
I assume, since you are talking about a point and not a plane, you mean left or right of the point along the world left-to-right axis?

If so, if you construct a vector running from the point out down the positive x axis, then take the dot product of that vector with the vector from the point to the player, the result will be >0 if the player is on the same side of the point as this new vector, and <0 if not.

vector v(1,0,0);
vector p=player-point;

if(dot(v,p)<0) // we are left
else if(dot(v,p)>0) // we are right
else // we are coplanar with the point

But could you clarify exactly in what sense they are left or right of the point? You would normally do this test for a plane, in which case there are equally well defined answers, but the plane would also have a defined orientation in the world, unlike a point.

Even then though, "left and right" are arbitrary. You would be checking to see whether you were in the positive or negative halfspace, which does not depend on the direction you are viewing from.

Share this post

Link to post
Share on other sites
Naah, that's the right way to do it.

However, if you're experienced enough you may prefer using Quaternions to do the job. It depends on what do you want to do inside if( right ) else if ( left ); I can't help you with quaternions if you don't tell why do you want to know if it's to the "right" or to the "left"


Dark Sylinc

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this