如何使用圆公式在Python中生成圆的一组坐标?

Rob*_*son 1 python geometry

希望使用用户指定的点生成圆的一组完整整数坐标,使用圆的公式:(xa)^2 + (yb)^2 = r^2

我怎样才能在 3d 空间中做到这一点,找到 x、y 和 z 的坐标。

QFS*_*FSW 5

参数化

\n\n

不要使用方程的笛卡尔格式,使用参数 one

\n\n

而不是 (xa)^2 + (yb)^2 = r^2,你有

\n\n

x = r * cos(t) + a

\n\n

y = r * sin(t) + b

\n\n

t,或更常见的三角函数 \xce\xb8,是 0 和 2\xcf\x80 之间的角度

\n\n

示例代码

\n\n
import math\n\na = 2\nb = 3\nr = 3\n\n#The lower this value the higher quality the circle is with more points generated\nstepSize = 0.1\n\n#Generated vertices\npositions = []\n\nt = 0\nwhile t < 2 * math.pi:\n    positions.append((r * math.cos(t) + a, r * math.sin(t) + b))\n    t += stepSize\n\nprint(positions)\n
Run Code Online (Sandbox Code Playgroud)\n\n

球体

\n\n

由于这是一个二维表面,因此需要第二个参数,因为一个参数是不够的

\n\n

u = [0, 2\xcf\x80]\nv = [-\xcf\x80/2, \xcf\x80/2]

\n\n

x = r * sin(u) * cos(v) + a

\n\n

y = r * cos(u) * cos(v) + b

\n\n

z = r * sin(v) + c

\n\n
import math\n\na = 2\nb = 3\nc = 7\nr = 3\n\n#The lower this value the higher quality the circle is with more points generated\nstepSize = 0.1\n\n#Generated vertices\npositions = []\n\nu = 0\nv = -math.pi/2\nwhile u < 2 * math.pi:\n    while v < math.pi/2:\n        positions.append((r * math.sin(u) * math.cos(v) + a, r * math.cos(u) * math.cos(v) + b, r * math.sin(v) +  c))\n        v += stepSize\n    u += stepSize\n\nprint(positions)\n
Run Code Online (Sandbox Code Playgroud)\n