How do i find the intersection between two torus ?

3 visualizaciones (últimos 30 días)
Duc Le
Duc Le el 18 de Feb. de 2020
Comentada: Duc Le el 20 de Feb. de 2020
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');

Respuesta aceptada

KSSV
KSSV el 18 de Feb. de 2020
  3 comentarios
KSSV
KSSV el 19 de Feb. de 2020
Did you try any of that....? It will work.....
Duc Le
Duc Le el 20 de Feb. de 2020
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by