I want to rotate a point around an origin that could be different from [0,0,0] (but axis don't change direction). Knowing the math, I did my try in MATLAB and everything works as expected.
P = [10 2 33];
O = [1 10 5];
O1 = [0 0 0];
B = zeros(3,100);
for i=1:100
c = cos(i/10);
s = sin(i/10);
Rz = [c -s 0; s c 0; 0 0 1];
A = P - O;
B(:,i) = Rz*A' + O';
end
plot3(B(1,:),B(2,:),B(3,:),'ob');
hold on
plot3(O(1),O(2),O(3),'or');
hold on
plot3(O1(1),O1(2),O1(3),'og');
Next I wanted to insert this thing into a bigger python script, so I wrote this code taking inspiration from this solution. The points that I want to rotate have their coordinates in self.line
, the origin is inside self.tvec2
, and both of them are continuously updated from the rest of the code
import numpy as np
#many other lines of code
theta = np.radians(1)
c, s = np.cos(theta), np.sin(theta)
Rz = np.matrix([[c, -s, 0], [s, c, 0], [0, 0, 1]])
self.line_T = self.line[:] - [self.tvec2[0], self.tvec2[1], 0]
print [self.tvec2[0], self.tvec2[1], 0]
for ii in range(self.line_T.shape[0]):
self.line[ii,:] = np.dot(Rz,self.line_T[ii,:]) + [self.tvec2[0], self.tvec2[1], 0]
The code works, but now it seems that self.line
is always rotates around [0,0,0], no matters what the value of self.tvec2
is (I use print
to check it out).
What is the problem? Where is my mistake? I am not an expert of numpy and python, but
np.dot(Rz,self.line_T[ii,:])
works, instead of this line with transposition
Rz*(self.line_T[ii,:].T)
and the result should be the same.
NB note that the third value of every coordinates, along Z axes, shouldn't be influenced by rotation around Z axes.