Jump to content

simple vector problem


Recommended Posts

Hello. I have two points. Each point has the same direction normal. I'd like to find out which of the two points is in front of the other, based on that direction normal. Is there a simple way to calculate this?

This is a 2D problem. Y is always 0 for both points, and the direction normal is always flat along the XZ plane.

simple_math_problem.jpg

Link to comment
Share on other sites

Hi,
you can compare angle between two vectors with dot product: the normal vector (v@N) and vector pointing from second point to the first one (v@difference = pt2 - pt1 , (pt1 and pt2 are positions of first and second point) ) and if angle is positive, then the second one is in front of, if negative, the second one is behind the first one.

Pseudo code could look like it

if (dot(v@N, v@difference) > 0) //second point is first
else //first point is first

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...