POV-Ray : Newsgroups : povray.off-topic : Bounding circle intersection : Re: Bounding circle intersection Server Time
4 Sep 2024 23:20:19 EDT (-0400)
  Re: Bounding circle intersection  
From: Slime
Date: 10 Dec 2009 21:53:30
Message: <4b21b42a$1@news.povray.org>
> float xDiff = x1 - x2;
> if (xDiff > rSum) return false;
>
> float yDiff = y1 - y2;
> if (yDiff > rSum) return false;
>
> if (xDiff + yDiff) < rSum return true;
>
> return (xDiff * xDiff + yDiff * yDiff < rSum * rsum)

I would want to make sure the additional branches don't make this slower. 
You also have to take the absolute value of xDiff and yDiff for the first 
two checks, which may add slowness. However, it may be worth it if you know 
it's extremely uncommon for the circles to overlap in the X or Y direction 
(which I suppose is a reasonable assumption).

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.