The underlying mathematics

Looking into the mathematics of the distance calculation, you may notice something interesting. The formula used for distance is as follows:

However, if we only need to compare the distance between points, the squared distance is all we need, as the following formula shows:

As the std::sqrt() operation is not required if we just want to compare distances to each other, we can omit it. The nice thing is, std::sqrt() is a relatively slow operation, meaning that if we compare a lot of distances between points, we can ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.