Skip to main content
gamedev.net
🔒 Locked

- Lines -

Started by Nazrix Sep 5, 2000 at 3:10 AM 2 replies 500+ views
Original Post
Nazrix
Nazrix
I can't remember how to do this: If I know the coordinates of 2 points, and use those points to make a line. Then I have the coordinates of another point, can I find out if that point is on the line with this info? If so, how? Thanks in advance Edited by - Nazrix on 9/5/00 3:19:10 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
wise_Guy
wise_Guy


Not sure how much you know

Okay, well lines are usually defined by y = mx + c. (well straight ones that is). m is the gradient and y is the x intercept.

If you use the top horizontal edge of your monitor as your positive x axis, and the left edge as your positive y axis, then it is easy to find specific points on the line, you can just sub in your values for x and y, and seeing that m and c are constant you can see if they are equal. if so, the point is on the line.

To find the rule in the form of y=mx+c, using 2 points, first you find the gradient.

point A (x1, y1) point B (x2, y2)

gradient = (y2-y1)/(x2-x1)

then you can sub in this value into your points so you have

y1 = gradient * x2 + c

you know all the other values except c here so its easy to find it. just do simple algebra. not sure how to do it in c though


I know this was overly complicated, but oh well...


wise_guy
Nazrix
Nazrix
Thanks a lot.

I was thinking somewhere along those lines (pun unintended, but quite welcomed), but I wasn't too sure...I should be able to take it from there



Edited by - Nazrix on September 5, 2000 4:37:57 AM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.