Draw and color the intersection between two 3D surfaces?
Afficher commentaires plus anciens
I want to draw, color, and shading (optional) the intersection between these two surfaces
- Surface 1:

- Surface 2:

I read many posts but I found none of them have the same idea I'm going for. I don't know exactly what to search for or what to read, everything seems a little confuse. Thanks.
2 commentaires
Star Strider
le 29 Juil 2023
This is either straightforward (if ‘x’ and ‘y’ are bounded to be between -1 and 1 and so can be expressed as trigonometric functions) or much more difficult (if they are unbounded and are allowed to be complex). In the first instance, ‘z’ is actually a volume (probably cylindrical) that extends from a (circular) plane equal to 1 to
.
Sejuani Sylaas
le 30 Juil 2023
Réponses (2)
In that event, the code would go something like this —
syms x y z theta
S1 = z <= sqrt(x^2+y^2)
S2 = x^2 + y^2 + (z-1)^2 <= 1
S1 = subs(S1, {x,y},{cos(theta),sin(theta)})
S2 = subs(S2, {x,y},{cos(theta),sin(theta)})
S1 = simplify(S1, 500)
S2 = simplify(S2, 500)
th = linspace(0, 2*pi).';
figure
surf((cos(th)*[1 1]), (sin(th)*[1 1]), (ones(size(th))*[-1 1]), 'FaceColor',[1 1 1]*0.5)
hold on
patch(cos(th)*[-1 1], sin(th)*[-1 1], ones(size(th))*[-1 1], [1 1 1]*0.5)
hold off
axis('equal')
view(30,30)
zt = zticks;
zticklabels(["-\infty" string(zt(2:end))])
.
Bruno Luong
le 30 Juil 2023
Modifié(e) : Bruno Luong
le 30 Juil 2023
It's sphere extruded by a cone
x = linspace(-1.1,1.1,129);
y = linspace(-1.1,1.1,129);
z = linspace(0,1.1,129);
[X,Y,Z] = meshgrid(x,y,z);
V = Z <= sqrt(X.^2 + Y.^2) & ...
X.^2 + Y.^2 + (Z-1).^2 <= 1;
isosurface(X, Y, Z, V, 0.5);
axis equal
1 commentaire
Bruno Luong
le 30 Juil 2023
Modifié(e) : Bruno Luong
le 31 Juil 2023
Now that we confirm the shape of the intersection, we can plot the surface boundary of the intersection usng customized patch
n = 20; % discretization parameters of spherical parts
W = allVL1(3, n); % FEX file https://www.mathworks.com/matlabcentral/fileexchange/17818-all-permutations-of-integers-with-sum-criteria
% Connectivity
XY = W*[0 1 0;
0 0 1].';
F=delaunay(XY);
XYZ = W/n;
XYZs = XYZ ./ sqrt(sum(XYZ.^2,2));
XYZc = XYZs;
XYZs(:,3) = 1-XYZs(:,3);
XYZc(:,3) = sqrt(sum(XYZc(:,1:2).^2,2));
close all
patcharg = {'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'gouraud'};
T = [0 -1 0;
1 0 0;
0 0 1];
for i = 0:3
patch('Faces', F, 'Vertices', XYZs, 'CData', XYZs(:,3), patcharg{:});
XYZs = XYZs*T';
patch('Faces', F, 'Vertices', XYZc, 'CData', XYZc(:,3), patcharg{:});
XYZc = XYZc*T';
end
view(3)
axis equal
With lighting set with camera toolbar

Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

