# 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.

## 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 on other sites
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 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 - x1Intercept 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 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 on other sites
Thanks guys, was a dumb question now i look at it. O well, once again, thanks.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634078
• Total Posts
3015362
×