# Adventures in 3D

I recently had the idea to create a model of the rings of Saturn. After a bit of reading, I learned that there are 14 major subdivisions of the rings. But each ring has lots of small variations in color. Unfortunately, I could not find any data that showed a more detailed breakdown of each of the major subdivisions. So, using some satellite images, I measured and recorded some of the more visible color differences, building out a data set as I went.

Like the image in the header of this post (from the Jet Propulsion Laboratory/NASA), pictures of the planet tend to show a sideways view. This often leads to people believing that the rings orbit the planet in an elliptical manner, similarly to the planets around the sun. But this is not the case—the rings, which are made up of billions of particles of various sizes, actually orbit Saturn in a circular manner.

So, to visualize the rings, I’d need to create circular polygons for each ring in my data set. These polygons would need to first draw an inner circle for the ring, then an outer circle, connecting them together, like this:

I also figured that I could create Saturn using a similar circular polygon. The only difference would be that the inner ring would have a radius of 0 (i.e. there would be no inner ring at all, so it would just be a solid circle).

To create each of the circles, I leveraged parametric equations (for more on these, see Beyond Show Me Part 3: Parametric Equations). In the end, I had what I think is a pretty cool top-down view of Saturn (click the image to interact with the full visualization).

**Going 3D**

But, I had bigger plans for this viz—I wanted to make it 3D and rotatable, which would allow you to see any angle of the planet and its rings. To do this, I’d have to add a 3

^{rd}dimension to the viz, then I’d leverage the work of Bora Beran to project the 3D coordinates (x, y, z) onto a 2D plane (x, y).
The first obstacle would be adding thickness to the rings. But I got lucky here. The rings have a thickness ranging from as little as 10 m to 1 km. When this is translated to my dashboard size of 1200 x 1200 pixels, that thickness would be less than a single pixel. So, I wouldn’t actually have to worry about the thickness at all.

The second obstacle would be making the planet itself 3D. I mulled over how to do this for a while. I could create a 3D sphere using methods outlined by Anya A’Hearn and Phillip Riggs in The 3D Tableau Full Monty, but I really wanted to avoid using an entirely different methodology to create the sphere than I was using to create my rings. Eventually, I realized that I could create a sphere by layering multiple circles on top of each other. I’d start with the circle I already had, then add layers above that (on the z axis) which slowly decrease in radius until they form the top of the sphere. I’d then do the same thing on the bottom of the main circle to form the bottom of the sphere. By doing this, then I’d be able to create this 3D model using nothing but circles.

The trickiest part of all this would be doing the math to calculate the z position and radius of each circle. I can feel people’s eyes rolling back in their heads already, so I’m not going to go into the math too much, but suffice to say that I realized that I could just turn the model over so that my z axis is in the position of a y axis and my x axis remains the same. Using trig, I could then calculate the radius and z position of each circle.

Once I had the math nailed, I attempted to create my sphere. For my first attempt, I created a data set with 500 records (one for each circle) and pre-calculated all my coordinates. I then visualized it in Tableau, colored the circles using the Hue Circle color palette, and created this:

The sphere can be rotated a full 360° in any direction. Here’s a gif of it being rotated:

After creating this, I wanted to see if I could create the same sphere using bins only. I was able to make it work, but the table calculations got a bit complex and that had a significant impact on performance, so I decided to stick with the pre-calculated data set.

**Making Saturn 3D**

So, now armed with the knowledge of how to create a sphere in Tableau with only circles, I returned to Saturn and applied the technique. I created 500 new records in my data set, then updated my viz. I then added some color variation to the circles in an attempt to show the cloud formations on the planet. Finally, I performed the 3D to 2D projection and rotated it so that I’d see a side view of the planet. And then…disappointment.

Part of the problem here is that my rings are not completely opaque, so the colors sort of bleed through, but there is a bigger problems that I had not accounted for—the z-order, which defines the ordering of overlapping objects. By default, Tableau wants to show one object on top of another object. When I first posted this blog, I had noted that this is a limitation of Tableau, that Tableau simply wasn't designed to do 3D. But, that's not exactly correct--rather, as Allan Walker pointed out to me, we just need the math to be able to calculate camera and its positioning. And he also noted that we can even change the position of the light source. So, even though I've personally hit a wall with this visualization, it's important to note that this is all possible with the right math.

**Why Do This?**

Before closing out this blog, I want to address the question some of you may be asking…why do this at all? Well, first of all, I just thought it would be cool to visualize Saturn. This may not necessarily be analytically insightful, but I thought it would be interesting and fun to create. Like a lot of my work, this is a bit more art than science. But, I am a big believer in the value of exploring the boundaries of Tableau. It forces you to think about problems in different and creative ways. And you’ll always learn something new about Tableau and how it thinks, as I have here. So while you may never have the need to create a sphere in Tableau, the lessons learned along the way and the skills you’ve gained will definitely be of value.

…and, if nothing else, I was able to create this really cool rotatable 3D eyeball ðŸ˜Š

Ken Flerlage, May 12, 2018

## No comments: