# Calculating coordinates

OK, I have a picture which will hopefully make my explanation a bit clearer.

I have a line $(a, b)$ to $(x, y)$ and all I know is the end points of the line.

I am trying to draw a line from the end point of the original line.

It will have an angle of $\theta$ from the original line and a length of $l$.

Based on these two values I need to work out the coordinates of the end point of this new line.

Length l can be any positive value. Angle theta can lie anywhere from $-80^\circ$ to $+80^\circ$.

::Gets out pen and paper and starts scribbling::

-
Hi, I'm just coming up with a possible solution at the moment. Didn't know where to start to begin with, getting there now though. – Fogmeister Dec 5 '12 at 23:09

First, find the x and y components of the line from (a,b) to (x,y).

If we draw a horizontal line from (x,y), we can see that the angle between the extension of the (a,b) to (x,y) line and the horizontal is equal to angle Q because they are alternate interior angles. Since we're given angle R, the angle between the line from (x,y) to (c,d) and the horizontal is Q - R.

Now that we have that angle, we can find the x and y components of the second line segment. The x component is $l \cos(R-Q)$ and the y component is $l \sin(Q-r)$.

Adding components, we find that if (a,b) is the origin, (c,d) is at: $$(x+l \cos(R-Q), y+l \sin(Q-R))$$

If (a,b) is not at the origin, we simply shift (c,d):

$$(c,d) = (a+x+l \cos(R-Q), b+y+l \sin(Q-R))$$

Note: $\angle Q = Tan^{-1}(y/x)$

-
That's a much more concise version of what I came up with! Thanks :D (I'll add my answer anyway, but I've accepted yours). – Fogmeister Dec 5 '12 at 23:21

OK, so after a lot of scribbling...

I came up with this...

The dotted lines represent lines parallel to the x and y axes.

OK, so.

m = x - a n = y - b

alpha = inverse tan (n/m)

so...

beta = alpha - theta

(oops, I forgot length l of the new line)

p = l cos(beta) q = l sin(beta)

SOOOOO...

c = x + p d = y + q

Phew!

-