A Question About Linear Interpolation

901 Views Asked by At

So lets say I have two points $A=(x_1, y_1, z_1)$ and $B=(x_2, y_2, z_2)$. $A$ and $B$ are each associated with some scalar value $K_1$ and $K_2$. $K_1$ is negative and $K_2$ is positive and all the $K$ values of the points along the line $AB$ linearly go from $K_1$ to $K_2$. How would I linearly interpolate between $A$ and $B$ to find the point $C$ between them whose $K$ value is $0$? Is there an easy way to code this assuming I have a point class?

1

There are 1 best solutions below

2
On BEST ANSWER

Hint: The line connecting A and B can be parameterized $(1-t)A + tB$, and there is some linear function $f(t) = k_1 + k_2 t$ such that $f(0) = K_1, f(1) = K_2$.

So then, $K_1 = f(0) = k_1$ and $K_2 = f(1) = K_1 + k_2$ so $k_2 = K_2 - K_1$. Set $f(t) = K_1 + (K_2 - K_1)t = 0$, and solve for $t = K_1/(K_1 - K_2)$. Thus, the point you're looking for is $(1 - K_1/(K_1 - K_2))A + K_1/(K_1 - K_2)B = (1/(K_1 - K_2))(-K_2 A + K_1 B)$