POV-Ray : Newsgroups : povray.general : Testing whether a shape intersects with another Server Time
31 Jul 2024 08:25:31 EDT (-0400)
  Testing whether a shape intersects with another (Message 11 to 12 of 12)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Tim Attwood
Subject: Re: Testing whether a shape intersects with another
Date: 5 Nov 2007 22:38:13
Message: <472fe1a5$1@news.povray.org>
>> what is obvious is that you missed he doesn't test for a point. He tests 
>> for an object being inside another.

This macro tests if two objects are touching with some accuracy.
You could check if an object is inside another completely by
testing against an inverse container object.

#macro collision(A B rez)
   #local result = false;
   #if (((min_extent(A).x > max_extent(B).x ) |
         (min_extent(B).x > max_extent(A).x ) |
         (min_extent(A).y > max_extent(B).y ) |
         (min_extent(B).y > max_extent(A).y ) |
         (min_extent(A).z > max_extent(B).z ) |
         (min_extent(B).z > max_extent(A).z ))=false)
      #local AB = intersection{object{A} object{B}};
      #local Mn = min_extent(AB);
      #local Mx = max_extent(AB);
      #local S1 = seed(1);
      #local Pt = VRand_In_Box(Mn, Mx, S1);
      #local cnt = 0;
      #while ((result = false) & (cnt < rez))
         #local Pt = VRand_In_Box(Mn, Mx, S1);
         #if (inside(AB, Pt))
            #local result = true;
         #end
         #local cnt = cnt + 1;
      #end
   #end
   result
#end

#declare sample1 = union {
   box {<0,0,0>,<1,1,1>}
   sphere{<0,1,0>,0.1}
   pigment{Red}
};

#declare sample2 = union {
   box {<0,0,0>,<1,1,1>}
   sphere{<1,0,0>,0.1}
   sphere{<0,0,0>,0.1}
   pigment{Blue}
   translate <-1.05,0.25,0>
};

#local result = collision(sample1 sample2 1000);


Post a reply to this message

From: Bryan Valencia
Subject: Re: Testing whether a shape intersects with another
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

<<< Previous 10 Messages Goto Initial 10 Messages

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