I have a CNC program that I need to see how close the machine points are to multiple lines drawn over the same pattern. What I need is a function that I can pass the points (with the decimal places) for the start and end of the line and the x value I'm looking for the y value to and get the y value for that point on the line (if they are on the line). The function doesn't need to validate that they are on the line as I'll only be passing the ones on the line.
This is what I found online but it's not working the way I need it to.
public static double GetY(double x, double aX, double aY, double m)
// Vertical line (y-values are always the same)
if ([login to view URL](m))
double c = (aY - aX) * m;
return m * x + c;
public static double CalculateSlope(double aX, double aY, double bX, double bY)
if (bY == aY)
return [login to view URL];
if (bX == aX)
return (bY - aY) / (bX - aX);
aX = 594.7664
aY = 63.5246
bX = 140.0116
bY = 63.5118
x = 140.0116
y should be 63.5118 but it's actually returning 0.001747275146958124.
x = 200 also returns 0.0034357708373827563 for y.
aX = 140.4297
aY = 62.4948
bX = 140.8548
bY = 61.4806
x = 140.4297
y should be 62.4948 but is returning -149.0995675
I've attached two sample files that I need it to work for.
The Rough [login to view URL] file gives the points for the lines.
Each line is calculated using the point on the current line and the point on the next line.
The points that I need to calculate (assuming they fall between the x on the first line and x on the next line) are in Machine points.csv.
There are the x points that could fall on the line from Rough [login to view URL] and I need to calculate for each point what the value of Y is.
12 pekerja bebas membida secara purata $31 untuk pekerjaan ini
HI. I am C# programmer and I just saw your posting. I have enough experience about C# programming. I am interested in your code and now I am analyzing your code. If I find the problem, I will contact you. Thank you.
Hello, Client! I read your project description and code carefully. I'm a C/C++/python and math expert. I can do this task in a short time. I wish that to discuss with you in detail for this project. Best regards.