how to solve an equation with coordinates

40 Views Asked by At

I have a given function:$(x_i, y_i) = p(x_a, y_a) + (1-p)(x_b, y_b)$

From this function I need to get $p$, which should be a value between 0 and 1.

In an attempt to solve this I found:

$(x_i, y_i) = p(x_a, y_a) + (1-p)(x_b, y_b)$

$(x_i, y_i) - (x_b, y_b) = p(x_a, y_a) - p(x_b, y_b)$

$(x_i, y_i) - (x_b, y_b) = p((x_a, y_a) - (x_b, y_b))$

$\frac{(x_i, y_i) - (x_b, y_b)}{(x_a, y_a) - (x_b, y_b)} = p$

$\frac{(x_i - x_b, y_i - y_b)}{(x_a - x_b, y_a - y_b)} = p$

Here I have no idea how to continue. My logical follow-up would be to divide the x and y components seperately, like this: $(\frac{x_i - x_b}{x_a - x_b},\frac{y_i - y_b}{y_a - y_b}) = p$

This makes no sense though, since I would get a coordinate as a result instead of a number.

2

There are 2 best solutions below

3
On BEST ANSWER

I think you might need to sit back and think about the problem more. Suppose $x_a \leq x_i \leq x_b$ and $y_a \leq y_i \leq y_b .$ Then take a look at what happens when $p$ moves from $0$ to $1.$

Pretty neat, eh?

So now that you see why you would want such a function (and take my word that such a function is very very handy) what we are saying is that if we are given such a $(x_i, y_i)$, then there must be such a $p.$ And since you saw what happens when we vary $p$, you know that you only have to find $p$ in one coordinate direction. So we can do as you did, but just for, say, the $x$'s.

This gives $$x_i = p x_a + (1 - p) x_b$$ so that $$p = \frac{x_i - x_b}{x_a - x_b}.$$ Now, you should have seen that this was the case pretty much right away... why?

0
On

Your proposal is close to correct, but the RHS should read $(p,p)$ because you are computing $p$ twice, from the $x$'s and from the $y$'s.

If it turns out that you get two distinct values, then your point $p_i$ is not located on the segment $p_ap_b$. Then you can either declare no solution, or use a "best fit" solution, f.i. by projecting $p_i$ orthogonally on the segment.