how to pass from x y z plane to toroidal coordinate?
8 views (last 30 days)
Show older comments
Hey guys,
I am trying to make the transition from x, y, z coordinate to toroidal coordinate.
I tried to write the following code but I didn't achieve to do correctly the transition.
Any idea how to fix fix
Thank you in advance
Code:
clear all
clc
subplot 121
% suppose we have a line in the x,y,z plane
x=linspace(-1,1,10)
y=linspace(-2,2,10)
z=linspace(-3,3,10)
plot3(x,y,z)
grid on
subplot 122
% first creat torous
r_i = 1; % inner radius
r_o = 3; % outer radius
theta = linspace(-pi,pi,20);
phi = linspace(0*pi,2*pi,20);
[thetaa,phii] = meshgrid(phi,theta);
xx = (r_o + r_i.*cos(phii)).*cos(thetaa);
yy = (r_o + r_i.*cos(phii)).*sin(thetaa);
zz = r_i.*sin(phii);
surf(xx,yy,zz,'Facealpha',0,'Edgealpha',0.3);
hold on
% second do the transformation from x,y,z plane to the Toroidal Coordinates
R=(r_i+r_o)/2
f=atan(y./x) %azimuthal angle
r=sqrt( (sqrt(x.^2+y.^2)-R).^2+z.^2) %
t=atan(z./(sqrt(x.^2+y.^2)-R))
plot3(r,t,f,'MarkerSize',50)
2 Comments
Bjorn Gustavsson
on 17 Nov 2022
It is not at all clear how you want to transform that line to your torus-surface. I know how to map the coordinates of the x-y plane (or the complex plane if you want) to a spherical surface:
theta = linspace(0*pi,pi,19);
phi = linspace(-pi,pi,25);
[phii,thetaa] = meshgrid(phi,theta);
r_i = 1;
xx = r_i.*cos(phii).*cos(thetaa);
yy = r_i.*cos(phii).*sin(thetaa);
zz = r_i+r_i.*sin(phii);
surf(xx,yy,zz,'Facealpha',0.2,'Edgealpha',0.3);
hold on
x=linspace(-1,1,10);
y=linspace(-1,1,10)+1;
phi_l = atan2(x,y);
theta_l = atan((x.^2+y.^2).^.5/(2*r_i));
plot(x,y,'g')
plot3(r_i*sin(phi_l).*sin(2*theta_l),r_i*cos(phi_l).*sin(2*theta_l),r_i-r_i*cos(2*theta_l),'g','linewidth',2)
azV = -157.04;
elV = 34;
view(azV,elV-5)
You might have to make a more explicit explanation. Perhaps it becomes easier if you plot both line and torus-surface in the same axes?
Answers (1)
John D'Errico
on 17 Nov 2022
You have a line in three dimensionas, and you want to find the equation of that line in a toroidal coordinate system?
First, what is the equation of a line? Most simply, I would do it parametrically. Perhaps like this, using vectors X0 and DX, as
X = X0 + DX*t
In terms of coordinates x,y, and z, you might write:
x = x0 + dx*t
y = z0 + dz*t
z = z0 + dz*t
In this link, we see some explanation of a toroidal coordinate system.
In fact, that link even gives a conversion to the toroidal coordinate system from Cartesian coordiantes, (x,y,z).
2 Comments
Bjorn Gustavsson
on 18 Nov 2022
Edited: Bjorn Gustavsson
on 18 Nov 2022
It should be as simple as stepping through the section Inverse_transformation, there you can take equation by equation to calculate the phi, but you'd use atan2, rho and tau from your x, y, and z points without much problems.
@John D'Errico: It never before occurred to me to move away from the torus-surface - so I learnt something today too. Now I wonder if this principle of moving away extends to other pastry-shaped things?
See Also
Categories
Find more on 2-D and 3-D Plots 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!