我正在尝试在画布中用二次曲线构建一个近乎完美的圆。我有这个功能可以围绕一个圆设置点并将它们与二次曲线连接起来:
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 坐标作为控制点):
我正在寻找一种方法来根据圆半径和点数自动计算控制点的位置...欢迎所有帮助