I calculate the ordinate y of the point on the line for a given abscissa x. The line is defined by the two coordinates of the end points (x0, y0) (x1, y1). Endpoint coordinates are floats, and the calculation must be accurate to float for use in the GPU.
Mathematics, and thus the naive realization, is trivial.
Let t = (x - x0) / (x1 - x0), then y = (1 - t) * y0 + t * y1 = y0 + t * (y1 - y0).
The problem is that x1 - x0 is small. As a result, a cancellation error will be introduced. In combination with one of x - x0 in division, I expect a significant error in t.
The question is, is there another way to determine y with better accuracy?
i.e. should you first calculate (x - x0) * (y1 - y0) and divide by (x1 - x0) after?
The difference y1 - y0 will always be large.
source
share