Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

adammil

Determining which side of a line a point is on

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

Assume that I have a line, represented by a segment (two sets of coordinates). It cuts my 2d plane in half. Say I have a third point on the plane.. Imagine I ''rotated'' my plane so that the line was vertical and it cut my plane into two parts, a left and right. (I''m not actually rotating the plane and don''t want to have to rotate all my points to figure the problem out What (hopefully simple and efficient) algorithm could I use to determine which side of a line a point is on? If the point lies exactly on the line, the algorithm should return a positive for whatever direction you asked (either left or right). Any help? Thanks in advance adamm@san.rr.com

Share this post


Link to post
Share on other sites
Advertisement
Simple, use vectors. More specifically the equation of a line in "Standard form" (At least I think it's standard form, could be wrong). Here is the Equation

Ax + By + C = 0

A is the i (or X) component of the unit normal of the line.
B is the j (or Y) component of the unit normal of the line.
C is the distance from the origin to the line along the normal vector.

Now plug in the x of your point in x and the y of the point in y and you get a value.

If the result is 0 the point is on the line
If the result is less than zero (negative) it is behind it.
If the result is greater than zero (positive) it is in front of the line.

If you have no idea what I am talking about I suggest you lean vectors and the equations for lines. This also comes in handy with planes since the equation for a plane is so similar.

-Omalacon

Edited by - Omalacon on May 9, 2000 10:02:08 PM

Share this post


Link to post
Share on other sites
Thanks a lot, I worked it out
I already had everything i needed in fact.. i cant believe i overlooked the solution

basically I already have the center of each triangle pre-calculated (i use it for the map-maker)
and i also have a function that checks for the intersection of two line segments

so i just check the line segment from the arbitrary point and the and the center of the triangle against each of the sides of the triangle
if it intersects, it cant be inside


adamm@san.rr.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!