Measuring Distances Between Bocce and Pallino Balls
A visit back to high school geometry
Last week, we chatted about bocce ball stats.
This week, we're going to take a trip back to high school geometry class and re-learn the Euclidean Distance formula.
Welcome to the 38 new subscribers! A huge thanks to those (shoutout to Alex, Andy, and Lolo) using their referral links to share this newsletter.
What I remember about high school geometry
I remember three things from high school geometry:
I had a crush on my teacher, so I paid attention a lot
We learned a lot about triangles and angles
The school's basketball star would eat an entire box of Tobasco Cheez-Its (very distracting) and then take a nap on his desk every time we had class
What is the Euclidean Distance Formula
The Euclidean Distance formula finds the distance between two points in 2D, 3D, or higher dimensions. It is the exact formula we need to determine the distance between the larger Bocce ball and the smaller Pallino ball.
Euclidean's formula and Pythagorean Theorem are closely related, both involving triangles.
Wikipedia defines the Euclidean Distance formula as:
If you're eager for more Euclidean and Pythagorean, here's the hookup to the Wikipedia page:
Bocce is primarily a 2-dimensional game. That formula written more simply for 2D Cartesian (x, y)-coordinates is:
D(x,y) = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )
Where point 1 is (x1, y1) and point 2 is (x2, y2).
And in Python code on Line 10:
Running those two test cases on Line 19 and Line 20:
Python has a number of libraries that implement the Euclidean Distance formula more efficiently:
Using the algorithm from one of these packages optimizes speed.
Determine distance between bocce balls
A couple weeks ago, I shared my computer vision pipeline for finding bocce balls in (x, y) space:
Once every ball has a coordinate, you can compute the distance between each Bocce ball and the Pallino using the Euclidean Distance formula. By comparing the distances, you will see which balls are closest or furthest and count them accordingly as IN/OUT.
Therefore, scoring Bocce ball computationally is super simple and relies on Euclidean's formula.
Coordinate systems are relative though. Is the coordinate relative to the camera (pixel coordinates) or are they relative to the court (court coordinates)? Translating the camera image pixel coordinates into court coordinates is quite simple — simply define your region of interest (ROI) for the court or portion of the court and then scale (multiply) according to your court dimensions.
The coordinate system I've defined for ABC's 8ft x 30ft Bocce court (extend it for your court's dimensions):
Now, using Euclidean's formula and this coordinate system, you can calculate the distance between any two balls on the court.
Updates from the lab
Thanks for reading!
I hope you had a great Thanksgiving holiday for those that reside in the USA.
I'm so thankful to have a home to live in. Some people are much less fortunate. Check out the fundraiser below which is raising money for the homeless in Chicago.
~ Digital Dave
💰🏘️ Lindsay S. (plays on the Courtside Karens, ThNB ABC team) is raising funds to help put an end to youth homelessness in Chicago. Click here to make a donation or DM her on FB to get on her list for Sleep Out 2023 where you pledge to sleep outside on a cold November night in Chicago to get a feel for what our homeless go through!