POV-Ray : Newsgroups : povray.general : Testing for intersection of two objects Server Time
1 Aug 2024 04:14:19 EDT (-0400)
  Testing for intersection of two objects (Message 21 to 21 of 21)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Tim Attwood
Subject: Re: Testing for intersection of two objects
Date: 27 Jul 2006 00:02:04
Message: <44c83abc$1@news.povray.org>
> you could make use of a trace, or feed the above rendering back in and use
> eval_pigment instead of the monkey.

Who needs a monkey when you have a computer?
This isn't perfect, as Warp pointed out, sometimes this method will fail
to detect intersecting objects. Mostly it works though.

#include "rand.inc"

#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

<<< Previous 10 Messages Goto Initial 10 Messages

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