Rotating a meshgrid in 3D
5 views (last 30 days)
Show older comments
Zubair Ghani
on 4 Mar 2021
Edited: Walter Roberson
on 5 Mar 2021
Ive got a meshgrid in 2d that i've been rotating so far. I want toe expand the mesh to 3d, and am having some trouble rotating it. This is how i've been doing it for 2D:
xLin = linspace(-10*scale/4,10*scale/4,200);
yLin = linspace(-10*scale/4,10*scale/4,200);
[x,y] = meshgrid(xLin,yLin); % create mesh
angle1 = -1*atan2(k1(1,2),k1(1,1));
XY1 = [x(:) y(:)];
R1=[cos(angle1) -sin(angle1); sin(angle1) cos(angle1)];
rotXY1=XY1*R1';
Xr1 = reshape(rotXY1(:,1), size(x,1), []);
Yr1 = reshape(rotXY1(:,2), size(y,1), []);
0 Comments
Accepted Answer
Walter Roberson
on 4 Mar 2021
Edited: Walter Roberson
on 5 Mar 2021
The 3d process is much the same, except that you build xyz columns and multiply by a 3x3 array.
It can be easier to use makeghtform to build an appropriate 4x4 matrix. To use the 4x4 matrix, pad the xyz with a column of ones before doing the multiplication. Using the 4x4 permits easier rotation around an arbitrary center.
t=makehgtform(appropriate stuff)
xyz1 = xyz; xyz1(:, 4)=1;
newxyz = (t*xyz1')';
0 Comments
More Answers (0)
See Also
Categories
Find more on Bounding Regions 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!