MATLAB Answers

How do i find the intersection between two torus ?

조회 수: 11(최근 30일)
Duc Le
Duc Le 18 Feb 2020
댓글: Duc Le 20 Feb 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:
% 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
daspect([1 1 1]) % preserves the shape of torus
colormap('jet') % change color appearance

  댓글 수: 0

로그인 to comment.

채택된 답변

KSSV 18 Feb 2020

  댓글 수: 3

Duc Le
Duc Le 19 Feb 2020
Thank you for your answer, but i need intersection in three-dimensional space, not the line of intersection
KSSV 19 Feb 2020
Did you try any of that....? It will work.....
Duc Le
Duc Le 20 Feb 2020
I tried the way you said but the results were not as expected
% 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.
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.

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by