• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Trigonometry, Rotation

Hi experts,

I'm looking for some help with trigonometry, more specifically rotating 4 points around a centre point.

I have a rectangle,  with centre point 0,0 and want to rotate this counter-clockwise a variable number of degrees.  Say 45 degrees for example.  The 4 points on the rectangle are 6,3 : -6,3 : -6,-3 : 6,3.

I know this involves sin and cos but I cannot figure out how to use these functions.

So, simply put - how do i work out the new coordinates for a rotation of 45 degrees for the above coordinates.

Any help would be appreciated.

Thanks in advance,
Eoin.
0
inema
Asked:
inema
  • 4
  • 2
  • 2
  • +1
1 Solution
 
InteractiveMindCommented:
New_Y = Old_Y * Sin ( angle )
New_X = Old_X * Cos ( angle )
0
 
InteractiveMindCommented:
So, rotating the point (6,3) CCW by 45°, would be result in the point:

  ( 6*Cos(45), 3*Sin(45) )  =~  ( 4.2, 2.12 )
0
 
NovaDenizenCommented:
Close but not quite, InteractiveMind.

New_Y = Old_Y * cos( angle ) + old_x * sin(angle)
New_X = Old_X * Cos ( angle ) - old_y*sin(angle)

Notice that when angle=0, the cos is 1 and the sin is 0, so new_x = old_x and new_y = old_y
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
inemaAuthor Commented:
I have read up a bit more about this:

Radius, from 0,0 to 6,3, using pythagoras' = 6.7
sqrt(6^2 + 3^2)
sqrt(45) = ~6.7

new_X = radius * cos (angle)
new_X = 6.7 * cos(45)
new_X = 2.1

new_Y = radius * sin (angle)
new_Y = 6.7 * sin(45)
new_Y = 6.4

so 6, 3 rotates to 2.1, 6.4 ?
Is this correct?

The other numbers are confusing me because of all this quadrant and negative number stuff, anyone have any ideas?

Thanks again,
Eoin
0
 
inemaAuthor Commented:
Forgot to add...

First i got the previous angle using Tan (angle) = Opposite / Adjacent

Tan (angle) = 3/6
Tan (angle) = 0.5
Angle = ~27 degrees

So new angle to work with is 27+45 = 72 degrees

I then used
radius * cos (new angle)
radius * sin (new angle)

Does this make sense? It looks correct on a poorly drawn excel spreadsheet i made :)
0
 
NovaDenizenCommented:
inema, my expressions work.

New_Y = Old_Y * cos + old_x * sin
New_X = Old_X * Cos - old_y*sin

new_x^2 + new_y^2 = (old_y*cos + old_x*sin)^2 + (old_x*cos - old_y*sin)^2
 = old_y^2 * cos^2 + 2*old_x*old_y*cos*sin + old_x^2*sin^2 + old_x^2*cos^2 - 2*old_x*old_y*cos*sin + old_y^2*sin^2
= old_y^2*(cos^2 + sin^2) + (2 - 2)*(old_x*old_y*cos_sin) + old_x*(cos^2 + sin^2)
new_x^2 + new_y^2 = old_y^2 + old_x^2
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You ought to have a look at polar and cartesian co-ordinates.  At present you are in cartesian co-ordinates (point specified by distance on x and y axes).  Polar co-ordinates are the distance and angle from a defined point/axis.  To rotate in polar co-ordinates about the center point all you do is add the angles together.

eg.
if the point is 2.5, 30 degrees after rotating by 45 degrees the point is now 2.5, 75 degrees.
0
 
inemaAuthor Commented:
NovaDenizen,
I used your expression for the top right point (6,3) and it worked.  However when I try the same expression for negative numbers the results are off.

I read a bit about quadrants and that they change positives and negatives depending on which one you are working in.  Can anyone elaborate?

AndyAinscow,
Thanks for your input, however I don't think polar co-ordinates will be beneficial as I have a cartesian map to work with - it might be one unneccessary complication too many ;)
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Two functions - one converts cartesian to polar and one converts polar to cartesian
0
 
inemaAuthor Commented:
okay, after doing some research on the polar/cartesian conversions i've found that this is what i was doing with my original calculations.

Thanks for the help guys.  Points go to Andy.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now