Advertisement Jump to content
Sign in to follow this  
Kustaz

Converting 1(X,Y) & 2(X,Y) to Y = Mx + C

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

how would I convert a vector, supplied in the format of two coordinates, into the linear equation form (Y = Mx + C)? PS: Explanation of the conversion process would be much appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You have two points so that means you can get the slope.

Once you have the slope then To find the intersect. plug one point into the standard equation and solve for C.

Share this post


Link to post
Share on other sites

Vectors A = {x1,y1} and B = {x2,y2}
__
Line AB in Cartesian format:

Gradient of a line is rise over run:

M = y2 - y1
-------
x2 - x1

Intercept is found by finding the vertical shift required to align the line with the vectors

y = M*x + c
=> c = y - M*x
=> c = y1 - M*x1 (or c = y2 - M*x2)

Share this post


Link to post
Share on other sites
M is the slope, given by the equation: m=(y2-y1)/(x2-x1).
After finding M, just get one of the two points' above mentioned coordinates and place them in the appropriate places in the equation, and solve for C (for example, if you took the point (x1,y1) - you'd do C=y1-mx1).
after this, just rebuild your equation using M and C you've just found.
Practical example:
assuming we got two points A(2,3) and B(4,5).
We'll first find the slope (M): m=(y2-y1)/(x2-x1)=(5-3)/(4-2)=2/2=1.
Now, we'll find C (I'll use point A coordinate's here): C=y1-mx1=3-1*2=3-2=1.
Now we'll rebuild our equation using M and C: y=x+1.
Have fun :] if anything isn't clear, feel free to ask...!

EDIT: had some calculation mistakes, but it's all fixed now...

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.

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!