How do I use a transform matrix to get a new matrix?
1 view (last 30 days)
Show older comments
If I generate a 3D cylinder using the cylinder function
[x,y,z]=cylinder(1,60);
I can rotate the surface object with handle-graphics
(makehgtform(..); % which displays in the surf() just fine.
I know that the tc.Matrix will supply a 4x4 transformation matrix which looks correct, but the dimensions of x,y,and z are 2x61. The x and y coordinates are two identical rows (of circles) and the z has one row for the bottom of the cylinder and one row for the top. Here is the problem: How do I use the generated 4x4 transform matrix to create a new matrix that has been transformed (rotated and translated) with the 6 rows of x,y,z?
R = makehgtform('xrotate',xRotation,...
'yrotate',yRotation,...
'zrotate',zRotation);
S = makehgtform('translate',...
[xTranslation, yTranslation, zTranslation]);
tc.Matrix = S*R;
I need the actual transformed vectors for analysis - not just the surf plot. I should be able to multiply
tc.Matrix * [x; y; z]
to obtain the new matrix but the multiple rows in x,y,z are problematic.
0 Comments
Accepted Answer
Star Strider
on 18 Jul 2016
This uses the rotate function, not the ‘makehgtform’ functions, but it should demonstrate how to get the rotated and transformed data:
[x,y,z]=cylinder(1,60);
figure(1)
hcyl = surf(x,y,x); % Plot Cylinder
rotate(hcyl, [1 1 0], 25); % Rotate Cyulinder
hcylrot = get(hcyl); % Handle
xrot = hcylrot.XData; % Get Rotated Data
4 Comments
Star Strider
on 18 Jul 2016
My pleasure!
It would help to see the relevant parts of your code. That way, I can experiment with it and probably provide a specific solution.
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!