Draw and color the intersection between two 3D surfaces?

12 views (last 30 days)
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 Comments
Star Strider
Star Strider on 29 Jul 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
Sejuani Sylaas on 30 Jul 2023
Yes you are correct and I also want to confirm that x and y are bounded to be between -1 and 1.
This is my first time using MATLAB for this kind of surface drawing task. So, I'm curious if you can give me some guidance to solve this problem? I really don't know where to start.

Sign in to comment.

Answers (2)

Star Strider
Star Strider on 30 Jul 2023
In that event, the code would go something like this —
syms x y z theta
S1 = z <= sqrt(x^2+y^2)
S1 = 
S2 = x^2 + y^2 + (z-1)^2 <= 1
S2 = 
S1 = subs(S1, {x,y},{cos(theta),sin(theta)})
S1 = 
S2 = subs(S2, {x,y},{cos(theta),sin(theta)})
S2 = 
S1 = simplify(S1, 500)
S1 = 
S2 = simplify(S2, 500)
S2 = 
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
Bruno Luong on 30 Jul 2023
Edited: Bruno Luong on 30 Jul 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 Comment
Bruno Luong
Bruno Luong on 30 Jul 2023
Edited: Bruno Luong on 31 Jul 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

Sign in to comment.

Tags

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!