Find intersection of a cone and sphere in 3D

14 visualizaciones (últimos 30 días)
Michael Lherbette
Michael Lherbette el 8 de Abr. de 2016
Hello all,
I am trying to simulate the movement of a cone over a plane. On this plane there is a sphere. The idea is simple: when the tip is moving on the plane it will reach the sphere. As soon as it reaches the sphere, the tip should go up, to remove the contact and so.
The problem is axial symetric so I know I can do it in 2D. However, I would like to solve the problem in 3D to make a nice gif for presentation.
from now I have the following code:
% Sample: sphere radius 30 nm
[as,bs,cs] = sphere;
figure(1)
surf(as*30e-9,bs*30e-9,cs*30e-9+30e-9)
% Plan z = 0
ap = linspace(-50e-9,50e-9,0.5e2)';
bp = ap;
[Ap,Bp] = meshgrid(ap,bp);
Cp = zeros(size(Ap));
hold on
surf(Ap,Bp,Cp)
% Tip: cone
r = 25e-9;
h = 75e-9;
m = h/r;
[R,A] = meshgrid(linspace(0,r,length(as)),linspace(0,2*pi,length(as)));
X = R .* cos(A);
Y = R .* sin(A);
Z = m*R;
% Cone around the z-axis, point at the edge of the plan
surf(X-50e-9,Y-50e-9,Z)
hold off
axis equal
Then with a double for loop I can move the tip along the plan.
How can I solve the distance between the cone and the sphere ? I tried the following
%Start movement
for i = 1 : length(Ap)
for j = 1 : length(Ap)
XX = X-Ap(i,j);
YY = Y-Bp(i,j);
ZZ = Z;
subplot(2,2,[1 3])
surf(as*30e-9,bs*30e-9,cs*30e-9+30e-9)
hold on
surf(Ap,Bp,Cp)
surf(XX,YY,ZZ)
axis([-75e-9 75e-9 -75e-9 75e-9 0 75e-9])
hold off
view(3); camlight; axis vis3d
subplot(2,2,[2 4])
c1 = bsxfun(@minus, XX(:), as(:)*30e-9');
c2 = bsxfun(@minus, YY(:), bs(:)*30e-9');
c3 = bsxfun(@minus, ZZ(:), cs(:)*30e-9'+30e-9);
r = sqrt(c1.^2 + c2.^2 + c3.^2);
surf(XX,YY,vec2mat(r,length(XX)))
hold on
surf(Ap,Bp,Cp)
axis([-75e-9 75e-9 -75e-9 75e-9 0 75e-9])
hold off
view(3)
pause(0.001)
end
end
However I don't get the results I have. I bet my reasoning is wrong and the equations used as well.
ML

Respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by