Rotate a vector by an angle
A vector (x, y) with angle A to the x axis
Rotate (x, y) by angle B to (x', y'), so the angle between vector(x', y') and the x axis is (A + B)
|
| (x', y')
| /
| /
| /B (x, y)
|/_A______________
Let the length of the vector be R
x = R * cosA
y = R * sinA
so cosA = x/R and sinA = y/R
x' = R * cos(A+B) = R * (cosA * cosB - sinA * sinB)
y' = R * sin(A + B) = R * (sinA * cosB + cosA * sinB)
Replace the cosA and sinA in, we get
x' = R * (x/R * cosB - y/R * sinB)
y' = R * (y/R * cosB + x/R * sinB)
i.e.
x' = xcosB - ysinB
y' = xsinB + ycosB
[[x'],[y']] = [[cosB, -sinB], [sinB, cosB]] <dot> [[x],[y]]
In python using numpy, define the rotation matrix as
mat = [[cosB, -sinB], [sinB, cosB]]
v1 = [[x],[y]]
then the v2 after rotation
v2 = np.dot(mat, v1)