matlab - Why does my 3 axes system coordinate orientation change x with y values? -
i using matlab , euler angles in order reorient 3axes coordinate system. specifically,
rz = [cos(ψ) sin(ψ) 0;-sin(ψ) cos(ψ) 0;0 0 1]; ry = [cos(φ) 0 -sin(φ);0 1 0;sin(φ) 0 cos(φ)]; rx = [1 0 0;0 cos(θ) -sin(θ);0 sin(θ) cos(θ)]; rtotal = rz*ry*rz
then loop through old system coordinates (x,y,z) , make vector coord_old. reoriented system (xn,yn,zn)
for i=1:size(num,1) coord_old = [x(i,1);y(i,1);z(i,1)]; coord_new = rtotal*coord_old; xn(i,1) = coord_new(1,1); yn(i,1) = coord_new(2,1); zn(i,1) = coord_new(3,1); end
my issue when θ,φ,ψ≃0 x->-y , y->x , when θ,φ≃0 , ψ=90 x , y not rotate! means when x,y should rotate don't , when shouldn't rotate stay were!
--edit-- example, when ψ=20.0871, φ=0.0580 , θ=0.0088 these results
see x->-y , y->x while z doesn't change @ all! thoughts?
ok, see 2 main problems here:
rtotal = rz*ry*rz
not want sincerz
multiplied twice. think meanrtotal = rz*ry*rx
.- your rotation matrix seems incorrect. check this wikipedia artice correct signs.
here corrected rotation matrix:
rz = [cos(psi) -sin(psi) 0; sin(psi) cos(psi) 0; 0 0 1]; ry = [cos(phi) 0 sin(phi); 0 1 0; -sin(phi) 0 cos(phi)]; rx = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)]; rtotal = rz*ry*rx;
with matrix correct results:
x=1; y=2; z=3; psi=0; phi=0; theta=0; [xn,yn,zn] >> 1 2 3 x=1; y=2; z=3; psi=90/180*pi; phi=0; theta=0; [xn,yn,zn] >> -2 1 3
and here full graphical example of cube in 3d-space:
% create cube (not in origin) dvert = [0 0 0; 0 1 0; 1 1 0; 1 0 0 ; ... 0 0 1; 0 1 1; 1 1 1; 1 0 1]; dside = [1 2 3 4; 2 6 7 3; 4 3 7 8; ... 1 5 8 4; 1 2 6 5; 5 6 7 8]; dcol = [0 0 1; 0 0.33 1; 0 0.66 1; ... 0 1 0.33; 0 1 0.66; 0 1 1]; % rotation angles psi = 20 /180*pi; % z phi = 45 /180*pi; % y theta = 0 /180*pi; % x % rotation matrix rz = [cos(psi) -sin(psi) 0; sin(psi) cos(psi) 0; 0 0 1]; ry = [cos(phi) 0 sin(phi); 0 1 0; -sin(phi) 0 cos(phi)]; rx = [1 0 0; 0 cos(theta) -sin(theta); 0 sin(theta) cos(theta)]; rtotal = rz*ry*rz; % apply rotation dvertnew = rtotal * dvert'; % plot cubes figure; patch('faces',dside,'vertices',dvert,'facecolor','flat','facevertexcdata',dcol); patch('faces',dside,'vertices',dvertnew','facecolor','flat','facevertexcdata',dcol); % customize view grid on; axis equal; view(30,30);
Comments
Post a Comment