Transformation matrix 3d beam: I have to do a function for a 3D beam structure 90 degrees rotation of the global to local axes. (the two beams are perpendicular to each other). This function appears to be correct but appears error in driver file.

13 views (last 30 days)
function T = transformation2(x1,y1,z1,x2,y2,z2,omega)
L=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2); % element length
Cx = (x2-x1)/L; %%%direction cosine
Cy = (y2-y1)/L; %%%direction cosine
Cz = (z2-z1)/L; %%%direction cosine
co = cos(omega);
so = sin(omega);
Cxz = sqrt(Cx^2 + Cz^2);
T1 = [ Cx Cy Cz
-(Cx*Cy*co+Cz*so)/Cxz Cxz*co -(Cy*Cz*co+Cx*so)/Cxz
(Cx*Cy*so-Cz*co)/Cxz -Cxz*so (Cy*Cz*so+Cx*co)/Cxz];
T=[ T1 0 0 0;...
0 T1 0 0;...
0 0 T1 0;...
0 0 0 T1];
end
  3 Comments
Michael
Michael on 30 Nov 2011
omega is the dihedral angle and is in radians yes....the error is :Error in ==> transformation2 at 17
L=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2); % element length

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 30 Nov 2011
You are going to get horzcat or vertcat dimension mismatches. Your T1 is 3 x 3, but you use it as if it were a 1 x 1 when you construct T.
You should possibly be using blkdiag() to construct the T array:
T = blkdiag(T1,T1,T1,T1);
  11 Comments
Walter Roberson
Walter Roberson on 1 Dec 2011
Your error would be consistent with you having started the program by pressing F5 or using the menu "run" command, or typing Transformation2 in to the command line and then pressing return.
What you need to do, is on the command line type
Transformation2(1,2,3,4,5,6,7)
except that you need to replace the 1 with the value you want for x1, replace the 2 with the value you want for y1, the 3 with the value for z1, the 4 with the value for x2, and so on.
Transformation2(rand(3,15), ... )
or whatever is appropriate for you situation.
Sean de Wolski
Sean de Wolski on 1 Dec 2011
What line of code do you use to call |Transformation2|?
I would guess it's not
T = Transformation2(10,10,10,20,20,20,pi/2) %or similar
i.e. 7 inputs - what is required. The reason I asked if you were passing at least four is because the error message says 'x2' is not defined and x2 is the fourth input argument. y1,z1 might also be undefined though. This would also mean you don't have the 'omega = omega*pi/180' line since that would mean you _are_ passing in seven arguments. Please edit your original question to reflect what you currently have, how you're calling the function, and the full text of the error message.

Sign in to comment.

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!