Elegant Development

For all your programming needs

Coding the Universe

| Comments

Space. There's a reason that NASA and SpaceX are extremely selective with their employees. This week I, along with three other Flatirons, have been working on a web application that would allow the user to see the stars that would be above them that night in their location. So far it's a simple one page application that grabs the user's location when they go the site, crunches the numbers, and displays the result. Sounds simple right? Wrong.

Well, not fully wrong. But partially wrong. The code isn't that complicated. Just a matter of passing around information from JavaScript to Rails and back again. That doesn't sound too hard, and it's really not. But there's one problem. . . getting the information.

Well, not all the information is hard to collect. Getting the user's location is simple. Using that information is hard. Think about it. We have the earth, right. And a person on that earth with a latitude and longitude. And let's just say that person happens to be at The Flatiron School, which has a location of 40°42'19.3"N 74°00'50.2"W. Suppose that very person decides to check out our website. As soon as they arrive their location information is collected using JavaScript. An AJAX call later, that information is available in a controller. Let's take a step back. We have the user's coordinates. As far as stars are concerned, what does that give us? Everything. At least, everything that we need from the user.

Our user wants to see the stars. So let's listen to a popular piece of business advice and "give the user what they want". How do we do that? Well, we have their location. Let's think about how that relates to the stars in question. The user can only see the stars that are above them at night. For simplification purposes, let's say that the person can see the stars above the plane tangent to their location on the earth. So how do we find what stars are above that plane given the person's latitude and longitude? "Projecting an Arbitrary Latitude and Longitude onto a Tangent Plane" by Ivan S. Ashcraft provides the mathematical formulas for finding the tangent plane given the information we have been provided with. However, since we need to find the stars above, below, or on that plane, we only really need the normal (or perpendicular) vector to the plane. Following Ashcraft's formulas we can get the i, j, and k components of that normal vector, which Ashcraft labels as A, B, and C. Now that we have the normal vector, we need to adjust it to use the coordinate system that our stars use, the Galactic coordinate system, which uses the sun as the center. Because of the earth's orientation in comparison to the Galactic coordinate system, we need to rotate the normal by -240 degrees. So we have the normal to the plane, but how do we figure out which stars are above that plane?

Finding out whether a star is above, below, or on the plane is simple, all we need to do is the dot product. For each star, we dot the coordinates with the i, j, and k components of the normal vector. This gives the following formula: Ax + By + Cz. If the result of this formula is positive, we know that the star is above the plane and therefore visible at the location. If the result is negative, the star is below the plane and not visible. If the result is 0, the star is on the plane, which for this situation we'll consider not visible. That wasn't too hard, now was it?

At the end of the day, the project wasn't too difficult. However, conceptualizing what we needed to do to the data that we had to achieve our desired results was extremely difficult. Especially with the added pressure of a week deadline. However, by staying cool and taking things one step at a time, my group and I successfully finished LUMENsee. Check it out!