# Calculate the position of Y when position X, distance to Y and the Angle is known

I'm trying to solve this problem:

On a regular x/y grid, I have a point A located at position 2,7 (X,Y).

I have to place a second point (B) on the grid (somewhere to the right of point A), but I only know the X coordinate of this point B, as well as the angle the eventual imaginary corner will make at point A.... Making sense? I must use the angle in the formula I'm seeking..

So here's the data I have:

Point A -> X=2, Y=7

Angle = 45

Point B -> X=20, Y=?

The values are just examples.. I'm looking for the Y value of Point B in any case..

I hope someone can help me figure this out.. I'm trying to implement this into PHP but I can't find the correct math formula...

Thanks!!!!

-
Two points don't form a corner, not even an eventual imaginary one. If you really mean a corner, you'll need another point. But I have a feeling you might actually mean the angle that the line through $A$ and $B$ forms with the $x$ direction? – joriki Apr 11 '11 at 21:40

Taking Joriki's interpretation of a badly asked question, if the angle between your line and the $x-axis$ is $\frac{\pi}{4}$ radians then its slope is $1$. So we are solving the equation

$\frac{y_B - 7}{20 - 2} = 1$, which means that $y_B = 18 + 7 = 25$.

Please ask the question properly it is very badly phrased and we don't know what you mean by an "imaginary corner".

-
I would guess this interpretation of corner as well. – Ross Millikan Jul 11 '11 at 4:40

My interpretation is that Roel K is seeking a point B with x-coordinate $20$ such that $\angle OAB = 45^{\circ}$ where $O$ is the origin. This explains his use of the word "corner". In that case...

Let $\alpha$ be the angle between $\langle 2,7 \rangle$ and the x-axis, which is $\arctan(\frac{7}{2}) \approx 74.055^{\circ}$.

Next, subtract* $a = 45^{\circ}$ from $\alpha$ and obtain $29.055^{\circ}$, which is the angle the new vector starting at A and ending at B will make with the x-axis. Furthermore, we know that $\displaystyle \frac{Y-7}{X-2} = \tan(29.055^{\circ})$, so algebraic manipulation gives us $Y = 18\tan(29.055^{\circ})+7 = 17$. Thus, the point you want is $B = (20,17)$.

In general, if $A = (x,y)$, $B = (X,Y)$, and $a$ is your chosen angle, then
$Y = \displaystyle (X-x)\tan \left( \arctan \left( \frac{y}{x} \right) \pm a \right)+y$.
Choose whether or not to add or subtract $a$ based on where your expected point should be.

*I assumed you wanted a point in the first quadrant.

-

There are two possible solutions depending on how you define the $\theta = 45\deg$ angle.

For the above, with $A=(x_A,y_A)$ and $D=(x_D,y_D)$ where $x_D$ is known, then

$$y_D = \dfrac{x_D y_A \cos \theta - (x_A^2-x_A x_D + y_A^2) \sin \theta}{x_A \cos \theta - y_A \sin \theta}$$

for the example given $y_D=-25.4$, for $x_A=2$, $y_A=7$ and $\theta=45\,\deg=\pi/4$.

For the case you need to find $C$, given $x_C$ use

$$y_C = \dfrac{x_C (y_A \cos \theta - x_A \sin \theta)}{x_A \cos \theta + y_A \sin \theta}$$

with the example above giving $y_C = 11.1111$.

PS I used homogeneous coordinates for the points and lines to arrive at the expressions. The diagram was made with the online tool GeoGebra.

-