You will need to formulate the x, y, and z-coordinate matrices manually and then plot them using the SURF function.
The SURF and MESH functions accept only one set of x, y, and z-coordinates, but in a toroid, (x,y) ordered pairs can have two corresponding z-coordinates. Therefore, to plot a toroid in MATLAB, you will need to plot the top and bottom halves as two separate surfaces on the same plot. For example:
theta = 0:pi/10:2*pi;
r = 2*pi:pi/20:3*pi;
[R,T] = meshgrid(r,theta);
Z_top = 2*sin(R);
Z_bottom = -2*sin(R);
[X,Y,Z] = pol2cart(T,R,Z_top);
surf(X,Y,Z);
hold on;
[X,Y,Z] = pol2cart(T,R,Z_bottom);
surf(X,Y,Z);
axis equal
shading interp
3 Comments
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_493169
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_493169
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_750555
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_750555
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_750573
Direct link to this comment
https://de.mathworks.com/matlabcentral/answers/95230-how-do-i-plot-a-toroid-in-matlab#comment_750573
Sign in to comment.