I have a euclidean vector a
sitting at the coordinates (0, 1)
. I want to rotate a
by 90 degrees (clockwise) around the origin: (0, 0)
.
If I have a proper understanding of how this should work, the resultant (x, y) coordinates after the rotation should be (1, 0)
. If I were to rotate it by 45 degrees (still clockwise) instead, I would have expected the resultant coordinates to be (0.707, 0.707)
.
theta = deg2rad(angle); cs = cos(theta); sn = sin(theta); x = x * cs - y * sn; y = x * sn + y * cs;
Using the above code, with an angle
value of 90.0 degrees, the resultant coordinates are: (-1, 1)
. And I am so damn confused. The examples seen in the following links represent the same formula shown above surely?
What have I done wrong? Or have I misunderstood how a vector is to be rotated?
Normally rotating vectors involves matrix math, but there's a really simple trick for rotating a 2D vector by 90° clockwise: just multiply the X part of the vector by -1, and then swap X and Y values.
If we represent the point (x,y) by the complex number x+iy, then we can rotate it 45 degrees clockwise simply by multiplying by the complex number (1−i)/√2 and then reading off their x and y coordinates.
2D Rotation is a process of rotating an object with respect to an angle in a two dimensional plane. Consider a point object O has to be rotated from one angle to another in a 2D plane. Let- Initial coordinates of the object O = (Xold, Yold)
Rotating a vector 90 degrees is particularily simple.
(x, y)
rotated 90 degrees around (0, 0)
is (-y, x)
.
If you want to rotate clockwise, you simply do it the other way around, getting (y, -x)
.
you should remove the vars from the function:
x = x * cs - y * sn; // now x is something different than original vector x y = x * sn + y * cs;
create new coordinates becomes, to avoid calculation of x before it reaches the second line:
px = x * cs - y * sn; py = x * sn + y * cs;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With