JavaScript 数学曲线—心形线

引子

双角线,接着尝试心形线(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});
}

参考资料

posted @ 2021-11-22 08:57  XXHolic  阅读(361)  评论(0编辑  收藏  举报