Urvesh
Urvesh

Reputation: 445

Why is angle of point (X, Y point) w.r.t origin after rotation is different than before rotation in Python?

I have two doubts. I have X and Y coordinates which I have listed below. I also have plotted coordinates as shown in picture below.

x = [0, 1, 1, 0, 0, 1]
y = [1, 1, 2, 2, 3, 3]

enter image description here

Now, I have decided to rotate the geometry in clockwise. Therefore, I have rotate all points at 45 degree (+ve) using below formula.

x_dash = x[i] * math.cos(theta) + y[i] * math.sin(theta)
y_dash = -x[i] * math.sin(theta) + y[i] * math.cos(theta)

After using above code (Formula), I got below results which shows new coordinate points after 45 degree clockwise rotation and after plotting, I got below plot.

x_dash = [0.8509035245341184, 1.3762255133518482, 2.2271290378859665, 1.7018070490682369, 2.552710573602355, 3.078032562420085]
y_dash = [0.5253219888177297, -0.3255815357163887, 0.19974045310134103, 1.0506439776354595, 1.575965966453189, 0.7250624419190707]

enter image description here

My questions:

(1) if I take two coordinates (X and Y) of one point and if I find an angle using theta = np.degrees(np.arctan2(y, x)), I did not get 45 degree. For example:

np.degrees(np.arctan2(0.5253219888177297, 0.8509035245341184))

Result: 31.68992191129556

However, when I found an angle of 1st point before rotation. np.degrees(np.arctan2(1, 0)), I got 90.0.

I would like to know the reason that why there is a differece between the angle of same point before and after the rotation.

(2) If I have a rotated geometry like in the 2nd picture and I do not know the angle of rotation. What should I do make that geometry without rotation (like in the first picture).

Kinldy help me with these questions.

Upvotes: 0

Views: 96

Answers (1)

Shreyas R
Shreyas R

Reputation: 31

By default, math.sin() and math.cos() assumes that the arguments are in radians. So, the code considers the angle of rotation as 45 radians, and not 45 degrees.

You can define theta as: theta = numpy.radians(45)

Hope this clarifies everything.

Upvotes: 2

Related Questions