I want to highlight the curve of intersection of the sphare and the plane x+y+z=0 by a thick blue curve. How to do that?

2 views (last 30 days)
I want to highlight the curve of intersection of the sphare and the plane by a thick blue curve. How to do that? I have tried to hightight in the last few line of the code below but it does not work................... where is the mistake
%% Sphere parametrizing in spherical coordinates
R = 1 ;
theta = linspace(0,2*pi) ;
phi = linspace(0,pi/2) ;
[T,P] = meshgrid(theta,phi) ;
X1 = R*cos(T).*sin(P) ;
Y1 = R*sin(T).*sin(P) ;
Z1 = R*cos(P) ;
zlim([0,5])
surf(X1,Y1,Z1,'EdgeColor','r', 'FaceColor', 'none', 'FaceAlpha', .5) ;
% plane
hold on
x1 = -1:0.5:1; x2 = -1:0.5:1;
[X Y] = meshgrid(x1,x2);
Z=-X-Y;
%mesh(X1,Y1,Z1,'FaceAlpha',.5)
surf(X, Y, Z);
zlim([-1.5,1.5]);
xlabel('x')
ylabel('y')
zlabel('z')
%%%%%%%%%%%%% to highlight the curve of intersection of the sphare and the plane by a blue curve
hold on
R = 1 ;
T = 0:0.5:2*pi ;
X2 = R*cos(T) ;
Y2 = R*sin(T) ;
Z2 = -X2-Y2 ;
plot3(X2,Y2,Z2,'b', 'LineWidth',2) ;

Accepted Answer

David Goodmanson
David Goodmanson on 11 Jun 2022
Edited: David Goodmanson on 11 Jun 2022
Hi Atom,
Your code doesn't work because if you multiply out X2^2 + Y2^2 + Z2^2, you don't get R^2. So that arc is not on the surface of the sphere. The correct arc can be gotten by taking the x,y,z column vector
R*[cos(T),sin(T),0]'
that does lie on the sphere and multiplying by an appropriate 3x3 rotation matrix to put that circular path into the plane x+y+z = 0. However, it can be seen that each of x,y,z is just a linear combination of cos(T) and sin(T), and with some fiddling around one can arrive at the following in place of what you have:
% don't need another hold on since the previous hold on still applies.
T = linspace(0,2*pi,100)
x = R*( cos(T)/sqrt(6) + sin(T)/sqrt(2));
y = R*( cos(T)/sqrt(6) - sin(T)/sqrt(2));
z = R*(-2*cos(T)/sqrt(6));
ind = z<0; % since it's a hemisphere, lop off the curve below z = 0
x(ind)=[]; y(ind)=[]; z(ind)=[];
plot3(x,y,z,'b','linewidth',5)
hold off
You could also restrict T to the appropriate range so that no z<0 points are created in the first place.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!