想要使用用户指定的点为圆生成一组整数坐标,使用圆的公式:(x-a)^ 2 +(y-b)^ 2 = r ^ 2
如何在3d空间中执行此操作,找到x,y和z的坐标。
答案 0 :(得分:1)
请勿使用方程式的笛卡尔格式,请使用parametric一个
而不是(x-a)^ 2 +(y-b)^ 2 = r ^ 2,你有
x = r * cos(t)+ a
y = r * sin(t)+ b
对于三角函数,θ更常见,θ是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)