# Calculating position along the hypotenuse

The blue dot moves, I know its x and y coordinates, and I also know that that causes the red dot to move along the triangle's hypotenuse in such a way that the red dot's y coordinate is always equal to the blue dot's y-coordinate.

How do I calculate the x value of the red dot's coordinate?

-
If the red dot starts at the bottom left vertex and the origin is there, $y_{\text{red}}/x_{\text{red}}$ is the slope of the hypotenuse. Modifications can be made if the red dot starts somewhere else and you know the initial coordinates. – David Mitra Dec 11 '11 at 20:21
Thanks @david-mitra. But how can I calculate the x values of the red dot's coordinate if I know the x and y values of the blue dot (and the slope of the hypotenuse)? – Eric Dec 11 '11 at 20:35
That's still not quite enough information. You also need to know where the triangle is on the plane. – Dustan Levenstein Dec 11 '11 at 20:39
@DustanLevenstein: Ok, well let's assume the leftmost vertex of the triangle is at 0,0. – Eric Dec 11 '11 at 20:53

Making the assumptions stated in the comments, and further that the lower leg of the triangle is horizontal as pictured, and $m$ is the slope of the hypotenuse.
Then $y_{\text{red}}/x_{\text{red}} = m$, $y_{\text{red}} = y_{\text{blue}}$. Solving gives $x_\text{red} = y_\text{blue}/m$.
Assume the base of the triangle is horizontal at with the vertex at $(0,0)$ and length $x$. Furthermore, the triangle is right with a height $h$. Define the coordinates of the blue point as $(x_1,y)$ and the red point as $(x_2,y)$. Then, we want $x_2$ as a function of the common y-cordinate.
From basic trig, the interior angle between side x and the hypotenuse is given by $sin^{-1}\left(\frac{h}{x}\right)=\theta$. Note that when the the blue dot is at any height $y$ , $0\leq y\leq h$, drawing a vertical line from the red dot to the base forms a similar triangle with height y and base $x_2$. The angle between the base and hypotenuse will simply be $\theta$. Thus, we have from basic trig:$$sin(\theta) = \frac{y}{x_2} \Rightarrow sin\left(sin^{-1}\left(\frac{h}{x}\right)\right) = \frac{y}{x_2} \Rightarrow x_2 = \frac{y\cdot h}{x}\;\;\;0\leq y \leq h$$ Which gives the x-cordinate of the red point in terms of the givens.