Visualization of a toroidal surface in Matlab

I have a problem that is twofold:

  • How to build a toroidal surface in MATLAB, given the large radius R and small radius a? To avoid confusion, this is a toroidal / poloidal coordinate system , as shown in the figure below, which I am talking about. Toroidal coordinate system

  • Now, at any point (phi, theta) on this surface, the small radius will be distorted by some value that I saved in the matrix. How do I draw this distorted surface? It can be easy as soon as I answer part 1, but this is my actual goal, so any part 1 solution that cannot handle it is completely useless to me.

If someone tells me how to make the image below, please do =)

+4
source share
2 answers

Turning to your first question: first you will need to determine the coordinates of your torus in toroidal coordinates (it seems natural!), And then convert it to Cartesian coordinates, since MATLAB expects all graphs to be plotted (unless you create a polar graph, of course) . So, we start by defining our toroidal coordinates:

aminor = 1.; % Torus minor radius Rmajor = 3.; % Torus major radius theta = linspace(-pi, pi, 64) ; % Poloidal angle phi = linspace(0., 2.*pi, 64) ; % Toroidal angle 

We need only one surface of the torus, so a small radius is a scalar. Now make a two-dimensional grid of these coordinates:

 [t, p] = meshgrid(phi, theta); 

and convert to 3D Cartesian coordinates using the formulas given on the Wikipedia page related to the question:

 x = (Rmajor + aminor.*cos(p)) .* cos(t); y = (Rmajor + aminor.*cos(p)) .* sin(t); z = aminor.*sin(p); 

Now we have our torus defined in 3D, we can build it with surf :

 surf(x, y, z) axis equal 

Proof!

Change To solve the second question, it depends on how you saved your distortions, but say that you have a matrix defined at each toroidal and poloidal point, you just need to multiply the constant, the distortion is a small radius. In the future, I create a distortion matrix that has the same dimensions as my toroidal and poloidal angular coordinate matrices, and which is usually distributed around the average value of 1 with FWHM 0.1:

 distortion = 1. + 0.1 * randn(64, 64); x = (Rmajor + aminor .* distortion .*cos(p)) .* cos(t); y = (Rmajor + aminor .* distortion .* cos(p)) .* sin(t); z = aminor.* distortion .* sin(p); surf(x, y, z) 

Result:

enter image description here

+10
source

You can do this with surf - just create matrices with x, y, z coordinates. The page you linked to has trigger equations to do this (they are exactly what you thought up 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 the matrix of the desired values โ€‹โ€‹of a small radius and a pointer to this matrix - i.e. tz(i,j) = sin(theta)*distortion(i,j) (but in all dimensions, obviously).

+1
source

Source: https://habr.com/ru/post/1413194/


All Articles