diamond turbine

# Jdinoto

## Shared posts

### Detailed visualization of NBA shot selection

**Nathan Yau**

JdinotoAmazingly detailed and well executed dataviz!

Sports loves conditional distributions. What does Joe Billy Bob typically do against such and such team? How does play differ in wins and losses? And a lot of the data is easily accessible, which makes it straightforward to answer these questions. Buckets, by Peter Beshai, uses NBA data to explore shot selection with plenty of conditionals.

The above is a partial view of Stephen Curry's shot selection. If you follow professional basketball, the shot chart shouldn't be too surprising, with lots of threes at a higher percentage than the league average.

You also get shot distributions for distance and position on the court. More conditionals, you say? You can select the specific games you're interested in (from the 2013-14 season), or choose the more common categories such as games the team won or lost.

Maybe you want to compare players. Buckets has you covered.

There's also a league-wide view and team multiples.

Basically, if you're into basketball, you'll be able to spend some time with this project. There's a lot to poke at.

**Tags:** basketball

### Playing detective with rolling shutter photos

A while back, my friend Britta sent me an interesting photo she took with her iPhone while on a trip in a turboprop plane. The photo looked similar to this one, with a strange view of the propellors due to the “rolling shutter” effect of the CMOS sensor in the iPhone camera.

This effect piqued my curiosity. Can we figure out the rate at which a propellor is spinning by analyzing this kind of photo? And can we figure out the real number of propellor blades in the photo? (You can scroll to the end for answers if you’re impatient!)

#### Learning more about the iPhone camera’s properties

To start my research, I found this example of rolling shutter effect in video, showing strings vibrating at known frequencies (musical notes):

The yellow arrow represents the width in pixels of the image, which I measured to be about 393 px (when full size). The red arrow represents the width in pixels of the “wavelength” of the wave, which is measured to be about 171 px (when full size). This length actually reflects a temporal wave more than it does a spatial one, as in the small circular opening of the guitar, the string practically vibrates up and down remaining horizontal. A low E string on a guitar is supposed to be about 82 Hz, but I measured it with Audacity to be closer to 81 Hz. Then since the wavelength (red) represents the number of pixels sweeped out by the rolling shutter in one period of the E string, we can compute the shutter sweep time (professionally called the readout time) of the front-facing camera in the iPhone 4.

\( (1/81\mbox{Hz}) /\frac{817-646}{934-541}\approx \boxed{28\mbox{ ms}.}\)

#### Describing the rolling shutter effect

Now we can explore what’s happening in the propellor image above. Let’s say the propellor is rotating (counterclockwise), and the shutter is rolling from left to right. We can look at what will happen on the top and bottom halves of the propellor separately. On the top side, the blades are moving *toward the rolling shutter*, so there will be a larger relative velocity between the two, and therefore more “collisions” between the shutter and the blades. This will result in a larger-than-normal blade count. On the other hand, the bottom of the propellor will be moving in the *same direction as the rolling shutter*, and thus the relative velocity is smaller. This results in fewer blades, and each blade (and the space between them) will be stretched out.

There is a subtlety here: the velocity of the blades is not uniform with respect to radius. This means that points toward the center of rotation have less velocity, and so the rolling shutter effect is less noticable there. In fact, on the lower side, there is a point at which the blade’s velocity matches the sweep rate. Something very special happens here, and we will examine this in detail later. Therefore we expect the propellor to look normal within some (possibly small) neighborhood of the axis, but at some point on the bottom a critical point is reached where the tangential velocity matches the sweep velocity. Below that point, the relative velocity becomes greater again, but in the opposite direction, so we can expect that text written on the blades would appear in reverse.

#### Coming up with a theoretical framework

To help illustrate this effect, let’s come up with a theoretical framework. Consider a unit disk, spinning about its center at angular velocity \(\omega\). We may draw radial blades on this disk to give the appearance of propellors. We may now consider a vertical line that sweeps from left to right at a constant rate \(v\). We will define \(s=\frac{v}{\omega}\). This is a satisfactory approach, since for any propellor, we may use a distance unit equal to the radius of the propellor, at which point \(s\) is defined unambiguously as a unitless parameter. In the following animations, I have animated what a 5-blade propellor would look like for various parameters of \(s\). These animations are made by a mathematical function written with standard functions in Mathematica via a time-dependent DensityPlot (function from \(\mathbb{R}^2\times [0,2\pi)\rightarrow \mathbb{R}\)). There are easier ways to do this, but I wanted to come up with a single mathematical function that would capture all the magic of the rolling shutter. The animation illustrates what a video of the propellor would look like, and also helps visualize what’s going on between the blades. If the video aspect seems confusing, you can also interpret these animations as showing how the pattern changes as the initial angle of the propellor (when the photo started to be taken) changes.

(s=10) Shutter rolls so quickly that the 5 blades of the propellor appear normal. This is within the intended regime of the camera:

(s=2) Blade arrangement still topologically correct, but geometrically stretched on the bottom, and compressed toward the top:

(s=1) The topological threshold. Beyond this point objects begin to tear:

(s=0.8) Past the topological threshold, we begin to see the bottom side of the blade moving in the “wrong” direction:

(s=0.3) All hell breaks loose. We can see the critical point is quite visible just under the center of rotation. Blades seem to join and be torn apart from this point. Propellors appear on one side (at about 4 o’clock), and disappear on the other side (at about eight o’clock).

(s=0.1) An extreme example where the critical point is not resolvable due to the centeral hub. Blades begin to look like planar waves moving from the right to the left:

#### Examining the motion of the blades

How can we examine the apparent motion of the blades in these animations? I will do this by quantifying the apparent velocity field of the blades in the above animations. What we can do first is define a function whose gradient results in the velocity field of the unwarped propellor. Since the velocity is always tangential, we want a function proportional to \(\theta\). This function is not continuous in the transition from \(\theta=2\pi\) to \(\theta=0\). This is of no concern to us because it is the gradient, in the end, that matters, and the gap can be filled in by continuity. Now we can suppose that we paint blades in angular wedges, delineating where each blade begins and ends. As in the animations above, by warping this image, we can see how the blades bend, and the direction perpendicular to the edges of the blades will be the apparent velocity of the “blade front”.

Define

\(\Phi(r,\theta)=\theta\).

The value of this function determines the angle of a point, but also the difference in function values between two angles tells us how much time it takes for the propeller to turn by this angle (times some angular speed which here I assume to be unity). We can deduce the velocity of the propeller by recognizing that the direction of the velocity is in the direction of the gradient of the function, while its magnitude is the distance between points divided by the time, which is actually the reciprocal of the magnitude of the gradient (since the gradient is the change in \(\Phi\)=time per change in distance).

Now consider the composition of this function with the coordinate map

\((r,\theta)\rightarrow(r,\theta-\frac{r}{s}\cos\theta)\).

The purpose of this map captures the fact that the horizontal position of the pixel in question determines how much *later* the pixel is being recorded from the “expected” time. Later in time means we must sample from a further clockwise angle, which seems strange at first, but makes sense if you think about it.

So the warped function becomes

\(\Phi’=\theta-\frac{r}{s}\cos\theta\),

The blade now looks warped, but we still perceive velocity as

\(\vec{\nabla}\Phi’=\frac{\partial}{\partial r}\left[\theta-\frac{r}{s}\cos\theta\right] \hat{r}+\frac{\partial}{\partial \theta}\left[\theta-\frac{r}{s}\cos\theta\right] \hat{\theta}=\frac{-\cos\theta}{s}\hat{r}+(\frac{1}{r}+\frac{\sin\theta}{s})\hat{\theta}\).

Sort of. While the gradient points in the correct direction, as the blade moves faster, the magnitude of the gradient becomes smaller. This is what I was explaining before about reciprocating the magnitude of the vectors to get the correct velocity. First let us convert to cartesian coordinates:

\(\vec{\nabla}\Phi’=-\frac{x^2+ys+y^2}{s(x^2+y^2)}\hat{x}+\frac{x}{s^2+y^2}\hat{y}\),

and then divide by the norm squared to account for this subtlety, giving

\(\boxed{\vec{v}(x,y)=\left\{\frac{-s(x^2+sy+y^2)}{x^2+(s+y)^2},\frac{s^2 x}{x^2+(s+y)^2}\right\}}\).

Here is a visualization of the vector field for s=0.5:

Let’s do some analysis on this flow. Let us find the stationary points by setting the components equal to zero. The second component forces \(x=0\), which forces \(y^2+sy=0\implies y=0 \mbox{ or } y=-s\). This means \(y=0\) remains the center of rotation, and \(y=-s\) is the “critical point” that we had been discussing earlier. This is the point at which the blades seem to collide and tear. You can see from the plot that the point is a “saddle point”, which explains why along one axis the blades crash together, while on another they rip apart. This is not a surprise, as we already decided this is the point where the tangential velocity of the blades equals the velocity of the rolling shutter, so \(v=\omega r=\omega s \implies r=s\), and clearly it has to be along \(x=0\) below the x-axis. Another interesting insight is where the broken shards of propellor appear and disappear, on the edges of the disk the propellor traces out. By reverting to our polar coordinate representation, we can rephrase the question as asking “at what point is the velocity completely radial?” This is accomplished by setting the \(\theta\) component to zero:

\(\left. 1+\frac{r}{s} \sin\theta\;\right|_{r=r_0}=0 \implies \boxed{\theta=-\sin^{-1}\frac{s}{r_0}}\),

which is a cool result because it means that the blade entrance, exit, and critical points are collinear, on a horizontal line.

#### Using this information to find answers

Now back to the original question: how you can forensically determine information about a rapidly spinning blade by taking a photograph with a CMOS camera? For example:

- How many blades does the propellor
*actually*have? - At what rate is the propellor spinning?

*First question: How many blades does the propellor actually have?*

If the propellor is spinning slowly enough, then the warping is minimal, so the blades can be counted normally. However, when \(s\) becomes less than the radius of the propellor, it is somewhat more difficult to understand what is going on. However, often this does not matter, because as long as the critical point is lower than the hub of the propellor, you can count the blades as they come out of the hub, which will give the right answer.

The problem arises when the critical point is within the hub. Here is a solution to that problem: count the upward-pointing blades, and subtract from that the number of downward-pointing blades. I’m using “upward” and downward loosely, as in some cases these blades may not literally be pointing in the direction I’m describing, but it’s the kind of thing you just have to get a feel for. This method works because the “upward-pointing” blades include true blades as well as fake blades. But fake blades, unlike real blades, extend downward, and therefore can be subtracted away. Here is an example using the “subtracted away” approach:

There are 9 blades on the top, and 4 on the bottom, giving (\9-4=5\), so five blades. Another way to see it is the red regions show the fake propellor blades that will be subtracted away, also indicating that there are five blades present on this propellor. This technique becomes much more useful when counting fast-spinning propellors. Aesthetically, this method is very similar to the Divergence Theorem, or Gauss’ Law in Electrostatics. Whatever goes out that does not come in is attributable to a source, which in this case is the collection of blades emanating from the hub of the propellor.

*Second question: At what rate is the propellor spinning?*

Suppose we are at the airport and we see a propellor and we are curious to its speed, but all we have is our CMOS camera. How can we determine the rotational speed of the propellor?

For the sake of argument, suppose the propellor spans across the entire width of the camera’s image sensor. First we determine the true number of blades using the method described above. Call this number \(n\). Now what we will do is count the number of blades from the appearing point to the vanishing point around the top (direction of larger number of blades). Call this number \(N\). Then \(N\) is \(n\) times larger than the number of times one particular blade passes by the rolling shutter. In this time, the shutter point has moved from the left side to the right side of the image, which means \(N/n\) is one half rotation larger than the true number of rotations (if you count to the appearing and vanishing points, it is slightly more than \(\frac{1}{2}\)more, but in practice this difference is usually negligible. If you’re concerned, you can count blades across the entire horizontal diameter). Therefore,

\(\mbox{# of rotations}=\frac{N}{n}-\frac{1}{2}\),

where “\(\mbox{# of rotations}\)” (abbreviated to \(\#_{rots}\)) represents the number of rotations that take place in the time the rolling shutter takes to sweep across the entire propellor region. This number can be related to \(s\).

\( s=\frac{\small\mbox{rolling shutter velocity}}{\omega}=\frac{2r/\small\mbox{time}}{2\pi \;\#_{rots}/\small\mbox{time}}=\frac{r}{\pi \;\#_{rots}}\).

#### Update (October 15, 2014)

For more mathematical exploration of this effect, check out “Rolling Shutters” by Jason Cole.

### The Boy Who Loved Math

**Nathan Yau**

The Boy Who Loved Math: The Improbable Life of Paul Erdős, written by Deborah Heiligman and illustrated by LeUyen Pham, is a kids' book on the life of the prolific mathematician and a boy's love of numbers.

Most people think of mathematicians as solitary, working away in isolation. And, it's true, many of them do. But Paul Erdos never followed the usual path. At the age of four, he could ask you when you were born and then calculate the number of seconds you had been alive in his head. But he didn't learn to butter his own bread until he turned twenty. Instead, he traveled around the world, from one mathematician to the next, collaborating on an astonishing number of publications. With a simple, lyrical text and richly layered illustrations, this is a beautiful introduction to the world of math and a fascinating look at the unique character traits that made "Uncle Paul" a great man.

Heck yeah. [via Boing Boing]

### Mid-week light entertainment: The Economist imitates USA Today

**junkcharts**

### The Pac-Man Drawings

**Stephen Von Worley**

Check out the maze from designer Toru Iwatani’s recently-divulged Pac-Man concept sketches, side-by-side with the final arcade version:

They’re different! Why? As the story goes, after one too many blind Tokyo alleys, Iwatani expunged dead ends from the prototype. A fortuitous accident in modulo-28 space created the tunnels. And the more expansive overall feel of the final maze? The details are hazy, but my sources whisper something about a retreat to the American Southwest. And peyote.

Of course, I made the last paragraph up, but whatever happened, thank you lucky star! For without Pac-Man’s addictive gameplay – amplified by the improved maze, no doubt – I might have never met his girlfriend: Ms. Pac-Man.

Oh, Ms. Pac-Man, and the crazy bowling alley days that we spent together! To preserve those precious memories, I shall model my labyrinthine countryside manor after her immaculate first level. Every detail will be included, from the power pellets and food on the floor to the roaming fruit and ghosts!

Except for Blinky. That dude’s a flippin’ bastard.

Wokka wokka wokka wokka wokka…

### Do you have a chart fetish? We are pretty sure my science teacher has a graph fetish, so maybe you two could get together sometime

**joberholtzer**

### What Works in Rich Media Mobile Advertising?

**Randy**

Celtra’s What Works in Rich Media Mobile Advertising? infographic provides marketers with a baseline for ad performance, helping them plan successful and effective mobile campaigns.

Celtra Inc, the industry leader for rich media advertising and analytics across mobile devices, has today unveiled a new infographic that highlights front-line advertising industry trends from the company’s first quarterly Mobile Rich Media Monitor Report.The data behind the infographic indicates that a well designed rich media experience that uses a store locator, games or social media has a direct and positive impact on consumer engagement and return on investment. In fact, rich media mobile advertisements drive double-digit engagement rates (12.8 percent on average) across all devices types, platforms and ad placements.Celtra’s infographic hones in on several key metrics including engagement rate, expand rate and click-through rate. The data also provides an in-depth look at ad feature performance for mobile rich media campaigns.

This design is the first in a quarterly series planned by Celtra to be released with their quarterly Rich Media Monitor Report. Each one will highlight a different insight from the information that Celtra publishes in the report.

It’s a clear design that walks the reader through the data and the conclusions step-by-step. There’s a lot of data included, but the data visualizations are easy to understand.

Thanks to Caitlin for sending in the link!