1. 程式人生 > 其它 >JavaScript 數學曲線—星形線

JavaScript 數學曲線—星形線

引子

連鎖螺線,接著嘗試星形線(Astroid)。

簡介

Johann Bernoulli 在 1691-1692 年首次討論了星形線。它也出現在 Leibniz 1715 年的信件中。它有時被稱為四尖瓣,很明顯因為它有四個尖。

Astroid 直到 1836 年才在維也納出版的一本書中獲得了現在的名稱。即使在 1836 年以後,文獻中也出現了各種名稱,包括 cubocycloid 和 paracycle 。

在笛卡爾座標系中公式描述:

其中 a 為常數。

繪製

引數化轉換:

這是示例,繪製主要邏輯程式碼:

function draw() {
  let a = 100, start = 0;
  let x = 0, y = 0, points = [];
  const acceleration = 0.1, max = 20;
  while (start <= max) {
    x = a * Math.pow(Math.cos(start), 3);
    y = a * Math.pow(Math.sin(start), 3);
    points.push([x, y]);
    start = start + acceleration;
  }
  // 實現把點繪製成線的方法
  line({ points: points});
}

參考資料