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

1 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2016-7-18
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 个评论
Star Strider
Star Strider 2016-7-18
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 2016-8-1
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by