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

Source: Internet
Author: User
Tags mathematical functions
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.

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.