Public Group

# Simple Math question about angle. How can you find the end coordinates of a rotated line?

This topic is 1219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here is the picture.

The line started at (0, 0) and has 40 pixels long, hence it ends at (40, 0). In case I rotate the line 30 degrees, in what coordinates the line will end?

I have tried to search over Google, perhaps I was not using the correct keyword, so that I never find the solution.

##### Share on other sites

Both of the posts above me give you information to find the solution. So don't dismiss them . Read the links they provided.

Down Below is the process for obtaining the solutions. A few other things you might want to look at to understand what I did here...

This is a trig circle. This graph will show you some very useful information that can provide shortcuts, as well as some insights when you take a trig class. This graph shows how angles and it's comparable radian format will act when inputed into the functions sin and cos.

When you read it, remember that X is usually seen as Cos, and Y is seen as Sin.
(Cos, Sin)

https://lelandmath.files.wordpress.com/2013/10/screen-shot-2013-10-14-at-7-19-46-pm.png

Let's begin.

With Theta being 30.
And our Axis is (0,0)

Because we start out with our objects reference frame rotation being zero, we can go ahead and remove the y component to get R.

PROOF
sqrt(r2 = 402 + 02) is r=40

So...

r = 40
Theta = 30 deg

So... Polar Co-ordinates (r,theta) are (40, 30degrees) respectively.

This equates too...

x = 40 * COS(30) = 40 * (31/2/2) = 20*31/2 =APROX= 35
y = 40 * SIN(30) = 40/2 = 20

After calculation you have new coordinates
(x,y) = (35,20)

A few notes. Notice that our endpoint is not on y? This is because a rotation conserves the line's original length. What happens in Trig is that you make a circle as you rotate upon a point.

https://www.mathsisfun.com/algebra/trigonometry.html

Keep in mind, if you are doing this for a game... this is going to be horrendously slow. Your best bet would be to use a matrix.

Edited by Tangletail

##### Share on other sites

Keep in mind, if you are doing this for a game... this is going to be horrendously slow. Your best bet would be to use a matrix.

This is pretty close to what a rotation matrix does, really. If you're only doing a z-axis rotation of a 2D point you may as well just extract the math.

Rotation of theta degrees around z-axis (this is exactly what a 2D rotation matrix would do, but without the matrix):

x = (x * cos(theta)) - (y * sin(theta))

y = (x * sin(theta)) + (y * cos(theta))

Matrices are handy because they allow multiple transforms to be concatenated into a single transform and then applied to several vertices without needing to repeat any of the work.

For example, if you want to rotate a lot of points by 30 degrees then your matrix is:

[cos(30), sin(30)]

[sin(30), -cos(30)]

Which is

[0.866, 0.5]

[0.5, -0.866]

Then the vector mul works out to:

x = (x * 0.866) + (y * 0.5)

y = (x * 0.5) - (y * 0.866)

For any 2D point/vector.

##### Share on other sites
Mmph. So it is... so it is. My product of stupidity at 4 am in the morning.

##### Share on other sites

x = (x * cos(theta)) - (y * sin(theta))
y = (x * sin(theta)) + (y * cos(theta))

I'd have done

xnew = (x * cos(theta)) - (y * sin(theta))
ynew = (x * sin(theta)) + (y * cos(theta))

For both of these equations, as the naive coder would accidentally use the same variable names for both the input and output which would produce faulty results.

Edited by nobodynews

##### Share on other sites

x = (x * cos(theta)) - (y * sin(theta))
y = (x * sin(theta)) + (y * cos(theta))

I'd have done

xnew = (x * cos(theta)) - (y * sin(theta))
ynew = (x * sin(theta)) + (y * cos(theta))

For both of these equations, as the naive coder would accidentally use the same variable names for both the input and output which would produce faulty results.

I got the negative sign in the wrong row of the matrix too.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633662
• Total Posts
3013228
×