JavaScript 数学曲线—心形线

425 阅读1分钟

引子

双角线,接着尝试心形线(Cardioid)。

简介

90-1

Cardioid 是 Castillon 在 1741 年《Philosophical Transactions of the Royal Societyin》的一篇论文中首次使用的名称,它是一条曲线,是圆周上一点绕着半径相等的圆的圆周旋转所形成的轨迹。

在笛卡尔坐标系中公式描述:

90-2

其中 a 为常数。

绘制

参数化转换:

90-3

这是示例,绘制主要逻辑代码:


function draw() {

let a = 40, start = 0;

let x = 0, y = 0, points = [];

const acceleration = 0.1, max = 40;

while (start <= max) {

const cal = 2 * start;

x = a * (2 * Math.cos(start) - Math.cos(cal));

y = a * (2 * Math.sin(start) - Math.sin(cal));

points.push([x, y]);

start = start + acceleration;

}

// 实现把点绘制成线的方法

line({ points: points});

}

参考资料

《增广贤文》中有这样几句:

人见白头嗔,我见白头喜。

多少少年亡,不到白头死。

以后要是还有人说头上有好多白头发,就直接念这几句。