Jump to content
  • Advertisement
Sign in to follow this  
notalentgeek

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

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the picture.

8LwYs3t.jpg

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 this post


Link to post
Share on other sites
Advertisement

Both of the posts above me give you information to find the solution. So don't dismiss them tongue.png. 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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. rolleyes.gif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!