How can I get curvature contour
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Amish
el 5 de Feb. de 2025
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 comentarios
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!