jeffThompson / CollisionDetection

A book and examples on collision detection
418 stars 53 forks source link

Reduce amount of sqrt calculations #9

Closed DingumBoingum closed 5 years ago

DingumBoingum commented 5 years ago

There are plenty of places where distances are compared, and both are first calculated using sqrt calculations, which are notoriously slow. Comparing the distances before the square root calculation will still yield accurate results when comparing length.

jeffThompson commented 5 years ago

Thanks for the suggestion! I've be unsure how much to optimize the code vs make it clear how it works. In this case, I think I'd keep the full calculation so we have an actual distance (and not just a comparison). But a section on optimization and more advanced collision methods is brewing, so if you have other ideas please let me know!