• Advertisement
Sign in to follow this  

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

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

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
vecFromPointToPlayer.Normalize()
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
vecCrossToPlayer.Normalize()
if(vecCrossToPlayer.x < 0)
{
//Ur on the left
}
else
{
//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
Advertisement
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.

[code]
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
[/code]

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"

Cheers

Dark Sylinc

Share this post


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

  • Advertisement