Jump to content
  • Advertisement
Sign in to follow this  
fredrik90

Point on a line

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

Hi How can I find out if a point is on a line. Like this. How can I check if a point lie above or below? here is a not accurate picture. The point is not accurate, I have just placed it on the side. I need the formula. This will be used to calculate the ILS(Instrument Landing System) approch on an airport. Thanks, Fredrik [Edited by - fredrik90 on October 13, 2005 11:58:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
just formulate your "Geraden-Gleichung" I don't the english word:

first take your start point:

(2;2) so this means 2 = a * 2 + b => b = 2(1-a)
than take the second point
(4;5) 5 = a * 4 + b => 5 = a * 4 + 2 - 2 * a => 5 = 2*a+2 => a = 1,5

=> back to one
b = -1

so than you have your result, each point on your line must solve the equatiton
y = 1.5 * x - 1

Share this post


Link to post
Share on other sites
i can write some code if you like but i need to know what format the line is in (equation, two points, one point + angle?).

Share this post


Link to post
Share on other sites
Take it easy!

In 2D, you only need to know how much is the angle between the point and the line.
Think about cosines and cross product, your problem would define as:

Point:
P = {x,y}

Line(two points:

L1 = {x1,y1}
L2 = {x2,y2}

So:

V1 = P - L1 = {x-x1,y-y1} = {vx1,vy1}
V2 = L2 - L1 = {x2-x1,y2-y1} = {vx2,vy2}

Cross product:

c = V1%V2 = vx1*vy2 - vy1*vx2


If c = 0 then the point is on the line.



Share this post


Link to post
Share on other sites
I did forgive this:

if c>0 then the point is above of the line.
And if c<0 then the point is under the line.

Cheers.

Share this post


Link to post
Share on other sites
Yes! of course.

The same thing extends to 3D.


Point:
P = {x,y,z}

Line(two points:

L1 = {x1,y1,z1}
L2 = {x2,y2,z2}

So:

V1 = P - L1 = {vx1,vy1,vz1}
V2 = L2 - L1 = {vx2,vy2,vz2}

Cross product:

C = V1.cross(V2) = {vy1*vz2 - vz1*vy2,
-(vx1*vz2 - vz1*vx2),
vx1*vy2 - vy1*vx2)}

So |C| = sin(r)*|V1||V2|, where r is the angle between vectors.

If the length of C is 0, then the point is on the line. It can be verify as:
C.x*C.x + C.y*C.y + C.z*C.z == 0.0

Hope It help you.





Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!