How can I get curvature contour
조회 수: 5 (최근 30일)
이전 댓글 표시
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 ?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!