Hacker News new | ask | show | jobs
by hnaccy 2085 days ago
I've always defaulted to squaring the radii for circle collision to avoid the sqrt.

Is it a premature optimization these days?

4 comments

No, it’s not premature. Skipping sqrt operations in the inner loops, which collision detection often is, is a generally good idea because the sqrt operation isn’t cheap.
This is not premature at all and it does not add complexity to the code, quite the opposite.
My 8-bit games just used rectangles; for circles I just overlapped two inside the geometry in a fat "+" shape. This was on a platform with pixel-accurate collision detection in hardware, and I always thought that the sloppy geometry-based detection was more fun for players.

N-squared for single-digit N worked just fine, too.

Historial note: To avoid sqrt, the Atari baseball cartridge went the 1897 Indiana legislature one better, using octagons as circles.

π ~= 3,314?

Unte im finyish du kaxa okwa bik, 4 600 mm bi wit dek xante im. Na desh kuwang, unte im 2 300 mm gova bik, unte 14 000 mm fo imim du gang im. - 1 Da Bosmang Da Bik Imalowda 7:23