How to bound at 3D surface within an ellipse?

7 次查看(过去 30 天)
Hello! I feel like I looked everywhere for my answer but I could not find a solution, although it may be a simple one. I am relatively new to MATLAB. Basically I have a hyperbolic surface that I want to 3d plot. However, I only want to plot the part of the surface that is within an ellipse. The other boundaries for the hyperbolic surface are written below. Is there a function that can do this for me? Thank you!
clc;
clear all;
%defining constants
E0= 22.232;
Emajor=22.032;
Eminor=15.574;
H0= 0.230;
syms x y z Hmajor(z) Hminor(z)
%First equation of the ellipse
eqn1 = ((x-(E0-28))/Emajor)^2 + ((z)/Eminor)^2 == 1;
fimplicit3(eqn1); %plot the ellipse
xlabel('X axis')
ylabel('Y axis')
hold on;
Hmajor(z) = E0 - (Emajor * (1 - (z/Eminor)^2)^0.5) - H0;
Hminor(z) = Hmajor(z) * tand(60);
% Second equation (hyperbola) using Hmajor(z) and Hminor(z)
eqn2 = ((x-H0)/Hmajor(z))^2 - (y/Hminor(z))^2 == 1;
interval=[0 50 -25 25 -20 0];
fimplicit3(eqn2,interval) %plot hyperbola over the ellipse plot
axis equal
xlabel('X axis')
ylabel('Y axis')
zlabel('Z axis')

回答(1 个)

Zinea
Zinea 2024-10-9
Hi Hope,
I understand that the goal is to plot a hyperbolic surface constrained within an elliptical region. This can be achieved by evaluating the hyperbola only where it satisfies the ellipse equation. The following are the steps to be followed:
  1. A 3D grid is created using meshgrid to evaluate the equations over a specified range.
[xGrid, yGrid, zGrid] = meshgrid(linspace(-25, 25, 50), linspace(-25, 25, 50), linspace(-20, 0, 50));
The following documentation link of “meshgrid” may be helpful:
2. A logical mask ellipseMask is calculated to determine which points lie inside the ellipse.
ellipseMask = ((xGrid-(E0-28))/Emajor).^2 + (zGrid/Eminor).^2;
3. The hyperbola equation is evaluated over the grid and the mask ellipseMask” is applied.
hyperbolaValues = real(((xGrid-H0)./Hmajor(zGrid)).^2 - (yGrid./Hminor(zGrid)).^2);
4. The full hyperbolic surface is plotted using isosurface.
isosurface(xGrid, yGrid, zGrid, hyperbolaValues, 0);
You may refer to the documentation of “isosurface” to know how to use it:
5. The ellipse is plotted similarly as above.
isosurface(xGrid, yGrid, zGrid, ellipseMask, 1);
6. The hyperbolic surface within the ellipse is calculated as below:
ellipseMask = ellipseMask <= 1;
constrainedHyperbolaValues = hyperbolaValues;
constrainedHyperbolaValues(~ellipseMask) = NaN;
7. Finally, the hyperbolic surface calculated above is plotted using isosurface”.
isosurface(xGrid, yGrid, zGrid, constrainedHyperbolaValues, 0);
Given below are the figures for the full hyperbolic surface (Fig 1), ellipse (Fig 2) and the hyperbolic surface within the ellipse (Fig 3) respectively:
Fig 1
Fig 2
Fig 3

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by