1.方程
(1)心形线的经典隐函数方程为:

(2)参数方程(更平滑的心形):

(3)极坐标心形线

(4)参数方程(3D心形)

(5)隐函数3D心形

2. MATLAB代码
Matlab
clc;close all;clear all;warning off;%清除变量
rand('seed', 100);
randn('seed', 100);
%% 绘制各种心形曲线
% (1)隐函数绘制心形线
figure;
fimplicit(@(x,y) (x.^2 + y.^2 - 1).^3 - x.^2 .* y.^3, ...
[-1.5, 1.5, -1, 1.5], 'LineWidth', 2, 'Color', 'r');
axis equal;
title('2D Heart Curve (Implicit Equation)');
grid on;
% (2)参数方程绘制心形
t = linspace(0, 2*pi, 1000);
x = 16 * sin(t).^3;
y = 13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t);
figure;
fill(x, y, 'r', 'EdgeColor', 'none'); % 填充红色
axis equal;
title('Parametric Heart Curve');
% (3)极坐标心形线
theta = linspace(0, 2*pi, 1000);
r = 1 - cos(theta);
figure;
polarplot(theta, r, 'r', 'LineWidth', 2);
title('Polar Heart (Cardioid)');
% (4)3D苹果曲面
[u, v] = meshgrid(linspace(0, 2*pi, 50), linspace(0, 2*pi, 50));
x = (1 - cos(u)) .* sin(u) .* cos(v);
y = (1 - cos(u)) .* sin(u) .* sin(v);
z = (1 - cos(u)) .* cos(u);
figure;
surf(x, y, z, 'FaceColor', 'r', 'EdgeColor', 'none');
axis equal; view(3);
title('3D Heart Surface');
light; lighting gouraud; % 添加光照效果
% (5)隐函数绘制3D心形
figure;
fimplicit3(@(x,y,z) (2*x.^2 + y.^2 + z.^2 - 1).^3 - 0.1*x.^2.*z.^3 - y.^2.*z.^3, ...
[-1.5, 1.5, -1.5, 1.5, -1, 1], 'FaceColor', 'r', 'EdgeColor', 'none');
axis equal; view(3);
title('3D Implicit Heart');
3.程序结果




