How do i find the intersection between two torus ?

3 次查看(过去 30 天)
I have 2 torus in three-dimensional space, and i need to find the intersection between them
R=9; % outer radius of torus
r=3; % inner tube radius
th=linspace(0,2*pi,36); % e.g. 36 partitions along perimeter of the tube
phi=linspace(0,2*pi,18); % e.g. 18 partitions along azimuth of torus
% we convert our vectors phi and th to [n x n] matrices with meshgrid command:
[Phi,Th]=meshgrid(phi,th);
% now we generate n x n matrices for x,y,z according to eqn of torus
x1= (R+r.*cos(Th)).*cos(Phi) +9;
y1= r.*sin(Th) ;
z1= (R+r.*cos(Th)).*sin(Phi);
daspect([1 1 1]) % preserves the shape of torus
colormap('jet') % change color appearance
hold on
x2= ((R+r.*cos(Th)).*cos(Phi))*cos(2*pi/3) - (r.*sin(Th))*sin(2*pi/3) - 4.5;
y2= ((R+r.*cos(Th)).*cos(Phi))*sin(2*pi/3) + (r.*sin(Th))*cos(2*pi/3) + 9*sin(pi/3);
z2= (R+r.*cos(Th)).*sin(Phi);
surf(x1,y1,z1); % plot surface
surf(x2,y2,z2);
daspect([1 1 1]) % preserves the shape of torus
colormap('jet') % change color appearance
title('Torus')
xlabel('X');ylabel('Y');zlabel('Z');

采纳的回答

KSSV
KSSV 2020-2-18
  3 个评论
KSSV
KSSV 2020-2-19
Did you try any of that....? It will work.....
Duc Le
Duc Le 2020-2-20
I tried the way you said but the results were not as expected
R1=9;
R2=3;
R=R1+R2;
r=R2;
% Define the input grid (in 3D)
[x1, y1, z1] = meshgrid(linspace(-30,30));
% Compute the implicitly defined function
f1 = (sqrt((x1-9).^2 + y1.^2)-R).^2 + z1.^2 - r^2;
f2 = (sqrt(x1.^2 + y1.^2)-R).^2 + z1.^2 - r^2;
[x2, y2, z2] = meshgrid(linspace(-30,30));
z2 = -((sqrt(x2.^2 + y2.^2)-R).^2) + r^2;
% Visualize the two surfaces.
patch(isosurface(x1, y1, z1, f1, 0), 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none');
patch(isosurface(x1, y1, z1, f2, 0), 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none');
view(3); camlight; axis vis3d;
% Find the difference field.
f3 = f1 - f2;
% Interpolate the difference field on the explicif1tly defined surface.
f3s = interp3(x1, y1, z1, f3, x2, y2, z2);
% Find the contour where the difference (on the surface) is zero.
C = contours(x2, y2, f3s, [0 0]);
% Extract the x- and y-locations from the contour matrix C.
xL = C(1, 2:end);
yL = C(2, 2:end);
% Interpolate on the first surface to find z-locations for the intersection line.
zL = interp2(x2, y2, z2, xL, yL);
% Visualize the line.
line(xL,yL,zL,'Color','k','LineWidth',3);
This is the view from top
And this is the view from other direction
but what i really want is the solid intersection between them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by