查找圆周上点的坐标

Finding Coordinates of Points on a Circle's Circumference

我想要实现的是存储构成圆周的所有点的坐标。我知道这几乎是不可能的,因为圆周上有无限多个点,但可以说我想存储在圆周上每 1 厘米后找到的坐标。圆的周长是 50 厘米,所以实际上我将在我的数组中存储 25 个值。

这是我目前尝试过的方法:

for(var degree=0;degree<360;degree++){
    var radians = degree * Math.PI/180;
    var x = center + radius * Math.cos(radians);
    var y = center + radius * Math.sin(radians);
    //x & y are the coordinates of points on the circumference
} 

但是我上面的代码没有按预期工作。非常感谢您的帮助!

为此,您需要按适当的步长(而不是递增)步进角度。因此,让我们通过以下方式定义我们的圈子:
x0,y0 - 圆心
r - 半径
d - 点的近似距离

现在我们可以利用圆的周长了:

n = ceil (2.0*M_PI*r / d); // integer number of points (rounded up)
da = 2.0*M_PI/n;           // floating angular step between points
for (a=0.0,i=0;i;<n;i++,a+=da)
  {
  x = x0 + r*cos(a);
  y = y0 + r*sin(a);
  // here x,y is your point
  }

抱歉,我没有在 javascript 中编码,所以代码在 C++ 中,所以只需更改语法以匹配您的语法 ...

但是,如果您想要所有光栅化像素,还有其他方法可以做到这一点(Bresenham、midpoint 等...)有些甚至不需要其他操作 +,- 参见: