Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a line that goes to x (x1) of 300, and then I rotate the line by -10 degrees. How can I get the new x (x0) of the rotated line?

Here's a picture to show what I mean:


Are there any books that would help me learn this stuff?

share|improve this question
You need to have y coordinates for your end values and a start point for your problem to be solvable, I'm pretty sure. If the length of your line varies, the end point ("x1") is going to be different. – Tetrad Sep 6 '11 at 15:24
I have them, but I don't have the correct equation. – Blunt Sep 7 '11 at 8:35

You should learn trigonometry on Khan Academy. We didn't yet learn it in the school, but I believe it has to do something with sines and cosines and tangents. The basic idea is that when you do a thing like that, you get a right triangle, where the hypotenuse is the line from your standpoint to x1. If you do sin(a), you would get the length of your desired line divided by the hypotenuse, I'm not sure I never really got into this and no one thought me, so this might be false. Check on the internet (although it's obvious that you get a right triangle and need to use trigonometry).

share|improve this answer
+1 Khan Academy is great! It didn't have the advanced stuff I needed when I was at university, but it does cover stuff like trig very well. – Byte56 Sep 6 '11 at 15:21

you can easily use a rotation matrix of -10deg to find your answer. check wikipage to learn how to create a rotation matrix. after that you only need to multiply rotation matrix into (300,0).

If I'm not mistaken for your problem you also need height of rectangle to find intersection point;

here is a sudo code that computes x1 for you:

x0 = 0;
y0 = rectHeight;
teta = 10 * pi / 180;

x1 = cos(teta) * x0 - sin(teta) * y0;
y1 = sin(teta) * x0 + cos(teta) * y0;

ratio = rectHeight / y1;

x1 = x1 * ratio;
y1 = y1 * ratio;

result = 300 + x1;
share|improve this answer
height of what rectangle? – Blunt Sep 6 '11 at 14:48
in your drawing you are rotating a line in a rectangle and trying to find intersection point. that's the rectangle I'm talking about. – Ali.S Sep 6 '11 at 15:00

If it is not on the line (which means the new line is not longer, just rotated), the x position is Length * sin (angle) and the y position is Length * cos(angle).

300 * sin (-10) = 52.09...
300 * cos (-10) = 295.44...

You must yourself switch the 52 to -52 as the sinus function doesn't do that.

So the answer should be (-52 , 295).

share|improve this answer
of course, this only works for a vertical line, otherwise use a rotation matrix like the answer made by Gajet – Valmond Sep 7 '11 at 12:20
and what is considered to be the center of rotation with this formula? It is not the center of the line actually the center of rotation :/ if it was, maybe this would be correct. – Blunt Sep 13 '11 at 9:38
well, the answer is relative to the base position, if you want to rotate around a certain point, just translate all vectors to that point, rotate and translate back (which you can multiply together in a matrix if you want). – Valmond Sep 13 '11 at 11:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.