POV-Ray : Newsgroups : povray.general : Testing whether a shape intersects with another : Re: Testing whether a shape intersects with another Server Time
31 Jul 2024 10:29:02 EDT (-0400)
  Re: Testing whether a shape intersects with another  
From: Bryan Valencia
Date: 6 Nov 2007 20:41:47
Message: <473117db$1@news.povray.org>
// Persistence of Vision Ray Tracer Scene Description File
// File: SphereIntersections.pov
// Vers: 3.6
// Desc: Placing Spheres without intersecting
// Date: 11/6/07
// Auth: Bryan Valencia



#declare Count=400;

#declare SphereCenters = array[Count];
#declare Radius = array[Count];

#include "math.inc"
#declare T=texture{
   pigment{color rgb 1}
}

camera{location <0,0,-40> look_at<0,0,0>}
light_source{<-1,1,-1>*1000 color rgb 1}

#declare R=seed(0);

#declare thisSphere=0;
#while (thisSphere<Count)

   #debug str(thisSphere,5,0)

   #declare SphereCenters[thisSphere]=<0,0,0>;
   #declare ok=false;
   #while (ok = false)
     //create a center
     #declare ThisCenter = 
(<rand(R),rand(R),rand(R)>-<rand(R),rand(R),rand(R)>)*30;
     #declare ThisRadius = rand(R)*4+1;

     //test against each previous center
     #declare ok=true;
     #declare A=0;
     #while (A<thisSphere)  //iterate over previous centers
       #declare D = VDist(ThisCenter, SphereCenters[A]);
       #if ( D< (ThisRadius+Radius[A]) )
         #declare ok=false;  //of they are closer than 2 then they 
intersect, things are not ok.
         #declare A=Count; //short-circuit the rest of the testing
       #end
       #declare A=A+1; //next sphere in list to test against
     #end
     //at this point if any are too close we will generate a new center.
     #debug "."  //print one dot per new random point generated.
   #end

   #debug "\n" //when the new center is accepted, new line.
   #declare SphereCenters[thisSphere]=ThisCenter; //add it to the list.
   #declare Radius[thisSphere] = ThisRadius;

   #declare thisSphere=thisSphere+1;
#end

//now lets make spheres out of the list.
#declare A=0;
#while (A<Count)
   #declare C = SphereCenters[A];
   sphere{ C,1 texture{T}}
   #declare A=A+1;
#end






-- 
Bryan Valencia

"I'd rather live with false hope than with false despair."


Post a reply to this message

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