This article illustrates the python implementation of the method of evenly distributing n points on the sphere. Share to everyone for your reference. The specific analysis is as follows:
A recent job has encountered a need to distribute 10000 or so points evenly on a sphere. The so-called uniform, that is, the distance between the two adjacent points as far as possible consistent.
My algorithm is based on the polyhedron to split the spherical surface, I chose the positive eight-face body.
1. The effect chart is as follows:
The 2.sphere.py code is as follows
#!/usr/bin/python
#-*-coding:utf-8-*-
Import Math
class Spherical (object):
' spherical coordinate system '
def __ Init__ (self, radial = 1.0, polar = 0.0, azimuthal = 0.0):
self.radial = radial self.polar
= Polar
Self.azimuth Al = Azimuthal
def tocartesian (self):
' right-angled coordinate system '
r = Math.sin (self.azimuthal) * self.radial
x = Math.Cos (self.polar) * r
y = Math.sin (self.polar) * r
z = Math.Cos (self.azimuthal) * self.radial return
x, Y, z
def splot (limit):
s = spherical ()
n = Int (Math.ceil (math.sqrt ((limit-2)/4))
Azimuthal = 0.5 * math.pi/n
for A in range (-N, n + 1):
s.polar = 0
size = (N-abs (a)) * 4 or 1
polar = 2 * Math.PI /size for
I in range (size):
yield S.tocartesian ()
s.polar + + Polar
S.azimuthal + = Azimuthal
For point in Splot (Input (')):
print ("%f%f%f"%)
I hope this article will help you with your Python programming.