46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
namespace DispenserCommon.Utils;
|
|
|
|
public class LineEquationUtil
|
|
{
|
|
public static double CalculateX(LineEquation lineEquation, double y)
|
|
{
|
|
return lineEquation.CalculateXCoordinate(y);
|
|
}
|
|
|
|
public static double CalculateY(LineEquation lineEquation, double x)
|
|
{
|
|
return lineEquation.CalculateYCoordinate(x);
|
|
}
|
|
|
|
public static LineEquation CreateLineEquation(double x1, double y1, double x2, double y2)
|
|
{
|
|
return new LineEquation(x1, y1, x2, y2);
|
|
}
|
|
|
|
public class LineEquation
|
|
{
|
|
public LineEquation(double x1, double y1, double x2, double y2)
|
|
{
|
|
CalculateSlopeAndIntercept(x1, y1, x2, y2);
|
|
}
|
|
|
|
public double Slope { get; private set; }
|
|
public double Intercept { get; private set; }
|
|
|
|
private void CalculateSlopeAndIntercept(double x1, double y1, double x2, double y2)
|
|
{
|
|
Slope = (y2 - y1) / (x2 - x1);
|
|
Intercept = y1 - Slope * x1;
|
|
}
|
|
|
|
public double CalculateXCoordinate(double y)
|
|
{
|
|
return (y - Intercept) / Slope;
|
|
}
|
|
|
|
public double CalculateYCoordinate(double x)
|
|
{
|
|
return Slope * x + Intercept;
|
|
}
|
|
}
|
|
} |