How to rotate a 2d plot about the z axis to create a 3d object

56 views (last 30 days)
Good afternoon everyone,
My goal with the code bellow is to somehow transfer the use of using a roation matrix to rotate my 2d plot about the z axis to hopefully create a closed, convex surface. The issue im having trouble with is how can this be accomplished, since originally we dont have a z coord? would we have to plot the snips of the rotation in spherical coords, then at the end transfer the spherical coords to rectangular? The code bellow will rotate a given vector about (0,0) with given degrees in 2d, how can I implement this in 3d? The 3d rotation matrix for the z axis will be at the bottom of the doc if it helps.
Thank you for the time!
Please, Please, let me know if you see anywhere I can improve my code, make it more efficent, faster, anything!
Yieldstr = 1000; % KPa, Sets the str for all following 2d Plots
minValue = -4*Yieldstr;
maxValue = 4*Yieldstr;
fidelity = Yieldstr/125; %able to use much higher fidelity in 2d
sigx = minValue:fidelity:maxValue;
sigy = sigx.';
VM = (1/(sqrt(2)) .* sqrt((sigx-sigy).^2 + (sigy).^2 +(-sigx).^2));
[x,y,~] = find(VM<Yieldstr);
PStress = [sigx(y).' sigy(x)];
A = boundary(PStress,0);
FirstC = PStress(A,1);
SecC = PStress(A,2); %all this block of code is doing is finding the boundary of our Pstress
Var = [FirstC SecC]; %then assigning it to a variable, I think it'll make it a bit easier in the future
Var = Var';
Num = length(Var(1,:));
for theta = 0:45:45
for i = 1:1:Num
S(1,1) = Var(1,i);
S(2,1) = Var(2,i);
% S(3,1) = 0;
Rz = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
P = Rz*S;
X(1,:) = P(1,:);
Y(2,:) = P(2,:);
scatter(X,Y);
hold on
end
end
hold off
%here is the rotation matrix for rotating about the z axis
%Rz = [cosd(theta) -sind(theta) 0 ; sind(theta) cosd(theta) 0; 0 0 1];

Accepted Answer

Matt J
Matt J on 14 Oct 2021
See the cylinder command.
t = 0:pi/10:2*pi;
r = 2 + cos(t);
[X,Y,Z] = cylinder(r);
plot(r,t), xlim([0,3])
surf(X,Y,Z)

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!