This article mainly introduces how to implement Python to evenly distribute n points on the sphere. it involves Python plotting techniques and calling related mathematical functions, which has some reference value, for more information about how to evenly distribute n points on the sphere, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
Recently, I encountered a requirement to evenly distribute about 10000 points on a sphere. The so-called uniformity means that the distance between adjacent two points should be as consistent as possible.
My algorithm is to split the sphere based on a positive polygon. I chose a positive al surface.
1. as follows:
2. the sphere. py code is as follows:
#! /Usr/bin/python #-*-coding: UTF-8-*-import mathclass Spherical (object): '''spherical coordinate ''' def _ init _ (self, radial = 1.0, polar = 0.0, azimuthal = 0.0): self. radial = radial self. polar = polar self. azimuthal = azimuthal def toCartesian (self): ''' to Cartesian coordinate ''' 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, zdef 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 + = azimuthalfor point in splot (input (''): print (" % f "% point)
I hope this article will help you with Python programming.