Linear Function: y = mx + b (2 points given) in code
In your posted code, you seem to have made a typo. This:
var m = (point2.Y - point1.Y) / (point2.X + point1.Y);
...should be:
var m = (point2.Y - point1.Y) / (point2.X - point1.X);
You want this:
public static float GetY(Vector2 point1, Vector2 point2, float x)
{
var dx = point2.X - point1.x; //This part has problem in your code
if (dx == 0)
return float.NaN;
var m = (point2.Y - point1.Y) / dx;
var b = point1.Y - (m * point1.X);
return m*x + b;
}
I would have thought that:
var m = (point2.Y - point1.Y) / (point2.X + point1.Y);
should be
var m = (point2.Y - point1.Y) / (point2.X - point1.X);
Gradient is the delta in Y divided by the delta in X.