I have two different codes trying to do the same thing below, I want to be able to take several poles [N 3] And create rotation matrix for each omega [n x 1], I'm trying to figure out how i want to go about the storage and manipulation of rotation matrix.
I have also tried to do this with 3D matrix, but have tried to not support some functions, a 3D matrix.
function [r] = rotation matrix (pole, omega)% omega = degree of rotation% pole = about xyz vector% pole [xyz] and reflecting pole to rotate omega Is radian x = poll (:, 1); I = Poll ((,, 2); Ez = Poll ((,, 3); %%% R11 = Pre * X * (1-cos (Omega)) + COS (Omega); % R12 = East * I * (1-cos (omega)) - Easy * sin (omega); % R13 = Pre * Easy * (1-cos (Omega)) + Eh * Sin (Omega); %% R21 = Ey * Ex * (1-cos (Omega)) + EZ * sin (Omega); % R22 = Ey * Ey * (1-cos (Omega)) + COS (Omega); % R23 = Ey * Ez * (1-cos (Omega)) - Pre * sin (Omega); %% R31 = Ez * Ex * (1-cos (Omega)) - I * sin (Omega); % R32 = Ez * Ey * (1-cos (Omega)) + Pre * sin (Omega); % R33 = Easy * Easy * (1-cos (Omega)) + COS (Omega); R11 = bsxfun (@ plus, bsxfan (@ bar, east, east), bsxfan (@ zero, 1, cos (omega)), cos (omega); r12 = bsxfun (@ zero, BSXFone ( @ Times, BSXFan (@bar, X, IE), BSXFON (@ZERO, 1, COS (Omega)), BSXFON (@ bar, EZ, sin (Omega)); R13 = BSXFan (@ plus, BSXFone ( @ Bar, bsxfan (@ bar, x, ez), bsxfan (@ zero, 1, cos (omega)), bsxfan (@times, i, sin (omega))); r21 = bsxfu N (@plus, bsxfan (@ bar, bsxfan (@ bar, i, x), bsxfan (@ zero, 1, cos (omega)), bsxfan (@ bar, eas, sin (omega))); r22 = Bsxfan (@plus, bsxfan (@ bar, ii, ii), bsxfan (@ cum, 1, cos (omega)), cos (omega)); r23 = bsxfun (@ zero, BSXFun ( @ Bar, bsxfan (@ bar, ii, ez), bsxfan (@ zero, 1, cos (omega)), bsxfan (@times, x, sin (omega))); r31 = bsxfun (@ zero, BSX Safen (@bar, BSXfan (@bar, EZ, East), BSXFan (@Zero, 1, Cause (Omega)), BSXFone (@bar, I, sin (Omega))); R32 = bsxfun (@ plus, BSXfan (@ bar, BSXfan (@ bar, EZ, I), BSXFan (@ zero, 1, cos (omega)), bsxfan (@bar, x, sin (omega))); R33 = bsxfun (@ plus, BSXfan (@ bar, BSXfan (@ bar, eas, ez), BSXFan (@ zero, 1, cos (omega)), cos (omega)); R = [R11 R12 R13; R21 R22 R23; R31 R32 R33];
Edit with advice from comments
For example if I have 2x3 matrix of vector [Xyz] = sph2cart (deg2rad (312), deg2rad (-37), 1) poles (:,:, 1) = [x, y, z]; Poles (:,:, 2) = [0.4, -0.3, 0.1]; Poles (:,:,, 3) = [-0.1, 0.4, -0.5];
and a 1x3 matrix of the angle by which I rotate
omega (:, 1) = digetorad (65); Omega (:,:, 2) = 0.92; Omega (:,:, 3) = 0.48;
and run the function rotation matrix (pole, omega)
R = rotation matrix (poles, omega)
I get this matrix of values as 3x3x3
R (:,:, 1) = 0.587503610427254 0.36230591007508 -0.72358408997131 -0.728553373601606 0.625997769999203 -0.278094900653973 0.352206600660266 0.690551388008664 0.631735143054941 Etc ... I now have some coordinates with this matrix 3x1x3 A (:,:, 1) = [-0.604 0.720 0.342] Will rotate '; A (:,,:, 2) = [-0.604 0.720 0.342] '; A (:,:,, 3) = [-0.604 0.720 0.342] ';
Now I will rotate these points, but it seems that I can not multiply the matrix.
& gt; & Gt; Error in using AP = R * input should be 2-D, or at least one input scaler should be. To calculate Elementwise TIMES, use TIMES instead (. *) Instead of & gt; & Gt; AP = R * An array dimension should match for the binary array op. Usage of bsxfun
also does not work because it returns 3x3 matrix, when it should be 3x1
ap = bsxfun (@ Times, R, A) AP (:,,, 1) = -0.354852180698061 -0.218832769685349 0.40704473934671-0.524558428993156 0.450718394399426 -0.200228328470861 0.120454657425811 0.236168574698963 0.21605341892479 etc ... My immediate solution is to build one for loop, this is probably not the most effective way is. for m = 1: length (poles) ap (m, :) = r (:,:, m) * a (:,:, m);
Comments
Post a Comment