circle containing greatest number of points

Started by
19 comments, last by Lutz 14 years, 1 month ago
One thing you might consider as a speed optimization is substituting the actual distance calculation with a less accurate heuristic, such as Carmack's inverse or the Manhattan distance metric. To be accurate, you'd still need to calculate the actual Euclidean distance if the result is inconclusive.
Advertisement
Quote:Original post by irreversible
One thing you might consider as a speed optimization is substituting the actual distance calculation with a less accurate heuristic, such as Carmack's inverse or the Manhattan distance metric. To be accurate, you'd still need to calculate the actual Euclidean distance if the result is inconclusive.

You never have to take the sqrt, you can always stay squared:
sqrt((x1-x2)^2 + (y1-y2)^2) < 0.5*r   <==>   (x1-x2)^2 + (y1-y2)^2 < 0.25 * r^2
Apart from that, I was always wondering whether there's still a point in Carmack's inverse today. That method was apparently developed in the early 1990 and used in Quake 3 in 1999, but that's more than 10 years ago. Today, FPUs are much more optimized and I'm wondering whether you don't loose more cycles tinkering with the imprecisions of the method than you actually win. Anyone tested this? Today, memory access and cache coherence is the real bottleneck in most apps.
There's a SSE instruction that finds the square root, so there's no need for the optimisation unless you're targeting an old machine.
Quote:Original post by taz0010
There's a SSE instruction that finds the square root, so there's no need for the optimisation unless you're targeting an old machine.

There's a SSE instruction that computes an approximated reciprocal of the square root (see rsqrtps). This probably means that Carmack's trick is now implemented in hardware.
ive heard that is true alvaro for what its worth :P
Seems my comment was owned twice over. Cheers, guys :)!
Quote:Original post by taz0010
There's a SSE instruction that finds the square root, so there's no need for the optimisation unless you're targeting an old machine.


I use distance calc extensively in my Boids simulator and profiled the Carmack trick, this one and the regular calculation. The 'optimizations' were actually slower than just running the distance calc.
As a newbie to gamedev.net, I'm delighted that see that postings receive such interest and attention. Something tells me I'm gonna like it here. :-)
Quote:Original post by alvaro
Quote:Original post by taz0010
There's a SSE instruction that finds the square root, so there's no need for the optimisation unless you're targeting an old machine.

There's a SSE instruction that computes an approximated reciprocal of the square root (see rsqrtps). This probably means that Carmack's trick is now implemented in hardware.


With the only catch being that it isn't actually Carmack's ;-) It's only famous because of him, but it's not actually his.
Quote:Original post by cache_hit
Quote:Original post by alvaro
Quote:Original post by taz0010
There's a SSE instruction that finds the square root, so there's no need for the optimisation unless you're targeting an old machine.

There's a SSE instruction that computes an approximated reciprocal of the square root (see rsqrtps). This probably means that Carmack's trick is now implemented in hardware.


With the only catch being that it isn't actually Carmack's ;-) It's only famous because of him, but it's not actually his.


Oh, I know. I am referring to it as "Carmack's trick" because that's the name that was used elsewhere in the thread. Sorry I seem to have added to the myth that it's Carmack's code. There is a kinda inconclusive article about the origin of the code here, which leaves me without a good name for it. Any suggestions?

This topic is closed to new replies.

Advertisement