Fixing the orientation

Unfortunately, this isn't a very interesting display yet. For one thing, the orientation of the data is based on the orientation of the phone while it was sitting in my pocket during the ride, which probably changed every time I sat down in a new coaster. I'd like to transform the data into a common reference frame, with $\hat{z}$ straight up, $\hat{x}$ forward (along the direction in which the car travels), and $\hat{y}$ 90 degrees left of the direction of travel, so that we can compare the direction of acceleration across different rides. Fortunately, we know a few things about roller coasters that we can use to figure out how to make this transformation.

First, we know that every coaster starts and ends at rest, with the only acceleration being that due to gravity, which is always vertical. Thus, we just need to find a section of time corresponding to a period of rest at the beginning or end of the ride, then rotate all of the acceleration vectors so that the value at that time period is along the z axis. I've annotated the region of resting data I chose for this coaster with a light blue rectangle in the graph above.

This rotation alone isn't enough to fully correct the orientation of the acclererations, since it only tells us which way is up, not which way is forward or backward relative to the car's travel. If that isn't obvious, just imagine being inside a sealed room sitting somewhere on Earth (physics majors love sealed boxes in uniform gravitational fields...). From the direction of gravity, you'd be able to tell which way was up or down, but you'd have no information about which was was, say, North or East without some other piece of data. However, if your room were suddenly tilted toward the North Pole, you would be able to observe the change in direction of gravity, and the direction of gravity before and after the tilt would be enough to figure out exactly which way was North.

Fortunately, roller coasters almost all do something very much like this. The first thing a coaster does after leaving the station is to go up a large hill to build up some potential energy. The side effect of this is that the direction of the acceleration felt by the occupants (and the phone recording data) shifts exactly forward relative to the direction of travel for the car. This gives us enough information to perform a second rotation and transform the acceleration data into the reference frame we wanted. I've highlighted the time during which this coaster tilts back to go up the hill in red.

The code to perform these rotations is found in Coaster.reorient() in coaster.py. The regions of rest and tilting back are annotated by hand in the notes.json file accompanying each raw data set.