Understanding the Universe through Code: Spiral galaxies
Tags: visualization, javascript, coding, math
Published: 2020-03-06 03:04:48

---
title: Understanding the Universe through Code: Spiral galaxies
published: true
description: Making use of coding and math to model and understand Universe
tags: #visualization #javascript #coding #math
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/fbfpkexs3xn4iqhdglwy.jpg
---

###Mathematical nature of our Universe

The Universe, from the tiniest to the largest scale that we have so far been capable of exploring, is mathematical in nature; and this has always fascinated me! It is because we could understand and exploit this, that we were able to develop technologies that would’ve been perceived to be nothing less than magic by our ancestors if they were here to see them. At present, using technology, we can communicate with our loved ones even on the other side of the globe at any time simply because our Universe obeys laws of quantum mechanics (We use transistors in our devices which were built by making use of laws of quantum mechanics) and we were lucky enough to understand the laws and use it to our advantage.

This means that if we are good at Mathematics, we can learn a lot about our Universe. Scientific geniuses who have come before us like Newton and Einstein made use of Mathematics to gain a very deep understanding of our Universe. But I think we are a bit luckier than people who lived before us because we are living in the age of computers. Computers help us do mathematics and calculations more easily and quickly which means we have an opportunity to understand the Universe better now.

###About this series of blog posts

In this blog series, I'm going to make an attempt to take up some interesting observations in the Universe and make use of the power of simple math and coding to gain more insights into them using visualizations.

I'll be using a Javascript library called [p5.js](http://p5js.org/) which is one of the easiest libraries to create visualizations on the web. If you want to get familiarized with p5, there is an amazing Youtube channel called [coding train](https://www.youtube.com/watch?v=8j0UDiN7my4&list=PLglp04UYZK_PrN6xWo_nJ-8kzyXDyFUwi) which will help you and you can also make use of their [documentation](https://p5js.org/reference/).

I'll be explaining a topic through a sequence of 2 blog posts. In the first, I'll illustrate the idea using visualizations and in the second, I'll explain in detail how those visualizations are created.

###Spiral arms of galaxies

![Spiral galaxy](https://cdn.spacetelescope.org/archives/images/thumb700x/opo0501a.jpg)

There won't be anybody who is not awestruck by the beauty of spiral galaxies. They are one of the most beautiful structures in the Universe that we have been able to observe. Today we are going to address the question of how galaxies get their beautiful spiral shape with the help of some simple simulations created using basic math and coding.

Unfortunately, even now, scientists don't fully understand how spiral galaxies get their shape. But some interesting theories have been developed to explain this out of which one of the most widely accepted is the [Density wave theory](https://en.wikipedia.org/wiki/Density_wave_theory).

According to this theory, the spiral arms of galaxies are the places where the density of the stars is relatively higher which is caused by gravitational effects within the galaxy. 

![Density wave theory](https://hedberg.ccnysites.cuny.edu/img454/galaxies/ellipses-rotated.jpg)

The Spiral arms can be modeled by using elliptical orbits that are tilted slightly as their radii grow as shown in the figure above.

I'm going to illustrate this idea using an app called [Dynamic learning](https://www.dynamiclearning.io/about). Dynamic learning is an open-source project/platform which aims at improving Science and Math education with the use of interactive visualizations.

### Open the [Lesson in Dynamic learning](https://www.dynamiclearning.io/workbookeditor/WFvSNq7YqQA4tX2xH) ( please view in desktop)

![Preview](https://raw.githubusercontent.com/JithinKS97/miniature-happiness/master/dl-preview.png)

I hope you got a basic idea of density wave theory and how it leads to the formation of spiral arms of galaxies.

In the next post, I'll get into the details of creating the visualizations itself !!!