キャンバスに二次曲線を持つほぼ完全な円を構築しようとしています。円の周りにポイントを設定し、それらを二次曲線で接続するこの機能があります。
function calcPointsCircle(cx, cy, radius, dashLength) {
var n = radius / dashLength,
alpha = Math.PI * 2 / n,
i = -1;
while (i < n) {
var theta = alpha * i,
theta2 = alpha * (i + 1);
points.push({
x : (Math.cos(theta) * radius) + cx,
y : (Math.sin(theta) * radius) + cy,
ex : (Math.cos(theta2) * radius) + cx,
ey : (Math.sin(theta2) * radius) + cy,
py : (Math.sin(theta) * radius) + cy
});
i+=2;
}
}
for (i = 0; i < points.length; i++) {
var p = points[i];
ctx.strokeStyle = '#fff';
ctx.quadraticCurveTo(p.x, p.py, p.x, p.y);
ctx.stroke();
}
動作しますが、線は現在まっすぐです (コントロール ポイントに x 座標と y 座標のポイントを使用しているため、これは明らかです)。
円の半径とポイントの数に基づいてコントロール ポイントの位置を自動的に計算する方法を探しています...すべてのヘルプは大歓迎です