How do I use a transform matrix to get a new matrix?

1 view (last 30 days)
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.

Accepted Answer

Star Strider
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
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.
Grant Sandy
Grant Sandy on 1 Aug 2016
Eventually, I created my own cylinder object with a meshgrid across the height (z) and the surface (theta). Then, I was able to rotate and translate the object and retrieve the Xdata, YData, and ZData like you recommended. The meshgrid was necessary because I need to find intersections between the cylinder and other objects of unknown geometry. Without meshgrid, I can't scan points along the height(z) to see if they are shared with the intersecting volumes. Now, my challenge is to create the same properties with a cube that contains a meshgrid on all 6 faces.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!