How can I get curvature contour

5 次查看(过去 30 天)
Teerapong Poltue
Teerapong Poltue 2020-11-4
回答: Amish 2025-2-5,10:39
I got my surface plot from
Schwarz = @(x,y,z) cos(x) + cos(y) + cos(z);
fimplicit3(Schwarz);
and now I would like to add my own contour line
which created base on curvature (k).
which k can be calculated by (the function of x, y, z)
syms x y z
f = cos(x) + cos(y) + cos(z);
fx = diff(f,x);
fy = diff(f,y);
fz = diff(f,z);
fxx = diff(fx,x);
fxy = diff(fx,y);
fxz = diff(fx,z);
fyx = diff(fy,x);
fyy = diff(fy,y);
fyz = diff(fy,z);
fzx = diff(fz,x);
fzy = diff(fz,y);
fzz = diff(fz,z);
mat = [fxx fxy fxz fx; fyx fyy fyz fy; fzx fzy fzz fz; fx fy fz 0];
no = det(mat);
de = (fx^2 + fy^2 + fz^2)^2;
k = de/no;
how can I add my curvature contour line ?

回答(1 个)

Amish
Amish 2025-2-5,10:39
Hi Teerapong,
In order to generate a curvature contour line to your 3D implicit surface plot in MATLAB, you will need to generate a grid of points over which to evaluate the curvature and then use the contour3 function to overlay curvature contours on the surface plot.
The following code tries to achieve the same:
Schwarz = @(x,y,z) cos(x) + cos(y) + cos(z);
% Define symbolic variables
syms x y z
f = cos(x) + cos(y) + cos(z);
fx = diff(f, x);
fy = diff(f, y);
fz = diff(f, z);
fxx = diff(fx, x);
fxy = diff(fx, y);
fxz = diff(fx, z);
fyy = diff(fy, y);
fyz = diff(fy, z);
fzz = diff(fz, z);
% Calculate curvature k
mat = [fxx fxy fxz fx; fxy fyy fyz fy; fxz fyz fzz fz; fx fy fz 0];
no = det(mat);
de = (fx^2 + fy^2 + fz^2)^2;
k = de / no;
% Convert symbolic expression to function handle
k_func = matlabFunction(k, 'Vars', [x, y, z]);
% Define a 2D grid on a specific plane, e.g., z = 0
zSlice = 0; % Choose a constant value for z
[xGrid, yGrid] = meshgrid(linspace(-pi, pi, 100));
% Evaluate curvature over the 2D grid
kValues = k_func(xGrid, yGrid, zSlice * ones(size(xGrid)));
% Plot the implicit surface
figure;
fimplicit3(Schwarz, [-pi, pi, -pi, pi, -pi, pi]);
hold on;
% Plot curvature contours on the z = 0 plane
contour3(xGrid, yGrid, zSlice * ones(size(xGrid)), kValues, 10, 'LineWidth', 1.5);
xlabel('x');
ylabel('y');
zlabel('z');
title('Surface with Curvature Contours on z = 0');
colorbar;
hold off;
The documentation for the contour3 function can be found at: https://www.mathworks.com/help/matlab/ref/contour3.html
Hope this helps

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by