Introduction

Following the double angle line , then try the heart-shaped line (Cardioid).

Introduction

90-1

Cardioid is the Castillon first used in a paper in "Philosophical Transactions of the Royal Societyin" in 1741. It is a curve, a track formed by a point on the circumference rotating around the circumference of a circle of equal radius.

The formula is described in the Cartesian coordinate system:

90-2

Where a is a constant.

draw

Parametric conversion:

90-3

This is the example , drawing the main logic code:

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});
}

Reference


XXHolic
363 声望1.1k 粉丝

[链接]