Page 2 of 2

Re: How would one check if a square is within a circle?

Posted: Thu Feb 18, 2021 5:57 pm
by ivan
I haven't looked it up, but ok I'll trust your solution, pgimeno. :)

Re: How would one check if a square is within a circle?

Posted: Thu Feb 18, 2021 9:20 pm
by darkfrei
pgimeno wrote: Thu Feb 18, 2021 5:20 pm If distance(corner, center)^2 > radius^2 then Return true -- at least one corner is out of circle

By cancelling the square root in distance() with the squaring above, you save four square roots. The radius^2 can be calculated once before the loop. I believe that's the protip that eliddell suggested.
I know, the (squared_distance(corner, center) > radius^2) is much faster :)