# Analyzing a LeBron dunk using decomposition and motion graphs – the lesson

Our students have spent the last couple of weeks mastering one of their favorite topics – basketball. I can safely say that despite their height disadvantage and general unfamiliarity with their rapidly growing limbs, most of them could probably school me in a game of one-on-one. I needed a way to bring the ball back into my court.

Fortunately, students have also been working on basic graphing in their math and science classes, and I’ve been itching for a lesson with which to introduce the computational thinking concept of decomposition. Throwing all of these ingredients in a cauldron and giving it a good stir, the following lesson began to emerge.

Take a look at this spectacular play by the Cleveland Cavaliers during Game 3 of the 2015 NBA Finals, highlighted here as the fourth best dunk of the series. There’s a lot going on! LeBron James snags a rebound and takes off across the court, slinging it to Matthew Dellavedova and crumpling the defensive attempt from Klay Thompson and Stephen Curry. It’s a four-way race down the court – but was this play really a contest of speed? Who ran the fastest? How fast was he running? And how can we possibly find out?

If your answer to that last question was “decomposition”, you’re either psychic, extremely intelligent, or you read the second paragraph of this post. Decomposition is breaking something difficult into pieces and working on one piece at a time. So let’s decompose this play a bit.

There are ten players on the court, but only four really involved in this fast break, so let’s focus only on James, Dellavedova, Thompson and Curry. The video is full of dynamic camera angles, overlaid graphics, flashing lights, spectators, music, narration… altogether an overwhelming amount of data coming at us. All we really need to know is where these players are during the play – from there, we can calculate their speed over time.

Over the past half decade, the NBA has been working with STATS to install SportVU player tracking technology into all thirty stadiums. Comprised of six cameras and a very smart computer, this system logs the position of every player (and the ball) 25 times per second. Last year, the NBA opened this data up to the public. Visiting stats.nba.com reveals an absolute goldmine of statistics, and with a little code, it’s possible to get at the movement data directly.

Most of the Python code I used for this lesson came directly from Savvas Tjortjoglou and his incredibly helpful blog post describing how to access and manipulate this movement data. With a bit of tweaking, I was able to generate the animations and graphs I needed. If you’re interested in my code, check out this companion post.

The first animation shows where each of our four players are over time, as well as where the ball is. This helps remove all of the distracting elements of the original video, and lets us better analyze the play. It’s easy to see that Curry is actually leading the pack for most of the play. We can also see how wisely the offense spreads to the outside of the court, while the defense gets tangled up in the middle.

With a bit more code, we can also generate motion graphs for each player to determine who is moving the fastest, how fast they are moving, and when they hit that speed.

In fact, we can animate these speed graphs as well. When all is said and done, we end up with a very cool (albeit a bit overwhelming at first) dashboard showing us the play, the animation of players’ positions over time, and all four speed graphs.

What can we glean from the above? Well I’m no basketball expert, but it looks to me like Thompson was running just about as fast as James and Dellavedova. I’d conjecture that James’ speed wasn’t the defining factor on this play after all. Students had some interesting theories on why Curry’s speed peaked so low – is he just a slow guy? Did he give up, knowing he couldn’t stop LeBron? Or was he already in the right spot as a defender?

To no one’s surprise, the lesson was a major hit with our students. Even beyond the thrill of getting to watch basketball highlights in math class, they were enthralled with the technology behind player tracking, intrigued by the code used to generate these animations, and as expected, much more successful at analyzing this play than I was, especially armed with all of this data. They learned how powerful decomposition is in helping break down a daunting problem; they learned about speed graphs and basketball strategy; and most importantly, they were excited about math (and then some!).

If you’d like to leverage this lesson in your own classroom, you can download the PowerPoint deck (with all of the videos embedded) and Word worksheet (reading and drawing speed graphs), and feel free to reach out with any questions!