Python implements the method of evenly distributing n points on the sphere _python

Source: Internet
Author: User
Tags cos sin

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.