Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Create 3-D Galactic Art with Matplotlib

Member-only storyLee VaughanFollowTowards Data Science--ShareIn a previous article, I demonstrated how you could use Python’s Tkinter GUI module to make 2-D galactic art using the equation for a logarithmic Spiral [1]. In this article, we’ll take things a step further and use Python’s primary plotting library, matplotlib, to produce attractive 3-D simulations of spiral galaxies. Besides being fun, this project is a great way to present the concept of logarithmic spirals to students.Logarithmic spirals are produced when natural objects grow geometrically. Some examples are galaxies, hurricanes, and pinecones. In the case of galaxies, these spirals are represented by the star-packed spiral arms.Because spirals radiate from a central point or pole, they can be graphed with polar coordinates. In this system, the (x, y) coordinates used in the more familiar Cartesian coordinate system are replaced by (r, Ɵ), where r is the distance from the pole (at 0, 0), and Ɵ (theta) is the angle measured counterclockwise from the x-axis.Using these terms, the polar equation for a logarithmic spiral is:where e is the base of natural logarithms, a is a scaling factor that controls the size, and b is a growth factor that controls the spiral’s “openness” and direction of growth.As in the previous article, we’ll model a four-armed spiral galaxy by using the logarithmic equation to draw a single spiral and then rotate and redraw the spiral three more times. To model the central core of the galaxy we’ll randomly distribute points in a sphere. To capture the “background glow” of the galaxy, we’ll randomly distribute small “stars” around the galactic disc.Finally, to make it all three-dimensional, we’ll randomly move stars in the galactic disc up and down a little, and then use matplotlib to display the results in a 3-D chart.----Towards Data ScienceAuthor of “Python Tools for Scientists,” “Impractical Python Projects,” and “Real World Python.” Former Senior Principal Scientist for ExxonMobil.Lee VaughaninTowards Data Science--Damian GilinTowards Data Science--22Giuseppe ScalamognainTowards Data Science--16Lee VaughaninTowards Data Science--2Khouloud El AlamiinTowards Data Science--18Nikhil VemuinMac O’Clock--30AL Anany--357Mike Erickson--1Cory Doctorow--36Thomas SmithinThe Generator--22HelpStatusWritersBlogCareersPrivacyTermsAboutText to speechTeams



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Create 3-D Galactic Art with Matplotlib

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×