[英]How to generate a set of co-ordinates for a circle in python using the circle formula?
希望使用用户指定的点为圆生成一组整数坐标,使用圆的公式:(xa)^2 + (yb)^2 = r^2
我怎样才能在 3d 空间中做到这一点,找到 x、y 和 z 的坐标。
不要使用方程的笛卡尔格式,使用参数格式
而不是有 (xa)^2 + (yb)^2 = r^2,你有
x = r * cos(t) + a
y = r * sin(t) + b
t,或更常见的三角函数,θ,是 0 和 2π 之间的角度
import math
a = 2
b = 3
r = 3
#The lower this value the higher quality the circle is with more points generated
stepSize = 0.1
#Generated vertices
positions = []
t = 0
while t < 2 * math.pi:
positions.append((r * math.cos(t) + a, r * math.sin(t) + b))
t += stepSize
print(positions)
由于这是一个二维表面,将需要第二个参数,因为一个不够
u = [0, 2π] v = [-π/2, π/2]
x = r * sin(u) * cos(v) + a
y = r * cos(u) * cos(v) + b
z = r * sin(v) + c
import math
a = 2
b = 3
c = 7
r = 3
#The lower this value the higher quality the circle is with more points generated
stepSize = 0.1
#Generated vertices
positions = []
u = 0
v = -math.pi/2
while u < 2 * math.pi:
while v < math.pi/2:
positions.append((r * math.sin(u) * math.cos(v) + a, r * math.cos(u) * math.cos(v) + b, r * math.sin(v) + c))
v += stepSize
u += stepSize
print(positions)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.