Visualizing a toroidal surface in Matlab

后端 未结 2 541
慢半拍i
慢半拍i 2020-12-16 06:10

I have a problem which is twofold:

  1. How do I plot a toroidal surface in MATLAB, given a major radius R and a minor radius a? To avoid confu

2条回答
  •  情书的邮戳
    2020-12-16 06:50

    You can do this with surf - just create matrices with the x,y,z coordinates. The page you linked to has the trig equations to do this (they are exactly what you'd come up with on your own - I wrote the code below before checking your link).

    R = 10;
    a = 3;
    tx=nan(41,21);
    ty=nan(41,21);
    tz=nan(41,21);
    for j=1:21
      for i=1:41
        phi = (i-1)*2*pi/40;
        theta = (j-1)*2*pi/20;
        tx(i,j)= cos(phi) * (R+cos(theta)*a);
        ty(i,j)= sin(phi) * (R+cos(theta)*a);
        tz(i,j)= sin(theta)*a;
      end
    end
    figure
    surf(tx,ty,tz)
    axis equal
    

    To distort the surface, replace the constant a with a matrix of the desired minor radius values, and index into that matrix - i.e. tz(i,j) = sin(theta)*distortion(i,j) (but in all dimensions, obviously).

提交回复
热议问题