POV-Ray : Newsgroups : povray.binaries.scene-files : Collision detector problem : Re: Collision detector problem Server Time
2 Sep 2024 00:17:52 EDT (-0400)
  Re: Collision detector problem  
From: Mike Williams
Date: 6 Jul 2003 20:40:54
Message: <5KbisAAYFMC$Ewz6@econym.demon.co.uk>
Wasn't it J?rg 'Yadgar' Bleimann who wrote:
>High!
>
>Since about two months I'm fiddling around with a PoV script to place
>randomly distributed objects on a plane without
>overlappings... as long as I restrained myself to spheres, it worked
>very well, even with random radii, but as I started to
>check random cubes for overlappings, the problems began.
>
>I'm pretty sure that the collision condition stated in lines 112 and 113
>is incomplete, as it checks only for the x and z
>coordinates of the lower left front corner and the upper right back
>corner, whereas the left back and right front corners
>should also be taken into consideration.

That's easy to do, you just add the tests for the other two corners

>But regardless of that, the condition even as it is now never becomes
>true - the warning statement given in line 114 is never
>displayed! What did I wrong?

As soon as you find one box that doesn't overlap you #define cflag=0
which causes you to jump out of the loop, so you ended up only testing
against the very first box. The code that was commented out, using a
second cflag2 control variable was nearly right except that it should
have been initially set to 0, not 1.

Here are the relevant lines corrected (German comments removed to
prevent line wrap)

        #declare cflag2=0; 
        #declare b=0;
        #while (b<a & cflag=1)
           #if   ((((objs[b][0]<objs[a][0]) & (objs[a][0]<objs[b][2])) 
                 & ((objs[b][1]<objs[a][1])  & (objs[a][1]<objs[b][3])))
               | (((objs[b][0]<objs[a][2]) & (objs[a][2]<objs[b][2])) 
                 & ((objs[b][1]<objs[a][3]) & (objs[a][3]<objs[b][3])))
               | (((objs[b][0]<objs[a][0]) & (objs[a][0]<objs[b][2])) 
                 & ((objs[b][1]<objs[a][3]) & (objs[a][3]<objs[b][3])))
               | (((objs[b][0]<objs[a][2]) & (objs[a][2]<objs[b][2])) 
                 & ((objs[b][1]<objs[a][1]) & (objs[a][1]<objs[b][3]))))
              #warning "Error! Cubes overlapping!"            
              #declare c=c+1;
              #declare cflag2=1;
           #else
              //#declare cflag=0;
              #declare c=0;
           #end
           #declare b=b+1;
        #end
        #if (cflag2=0)
          #declare cflag=0;
        #end

Unfortunately, this still isn't quite sufficient, because it is possible
for cubes of different sizes to overlap without any corners of [a] being
inside [b]. There's an example in the upper left where a grey box [a]
lies on top of a red box [b].

For as complete check you can do this:-

        #declare cflag2=0; 
        #declare b=0;
        #while (b<a & cflag=1)
           #if   ((objs[b][2]>objs[a][0]) & (objs[b][0]<objs[a][2])
               &  (objs[b][3]>objs[a][1]) & (objs[b][1]<objs[a][3]))
              #warning "Error! Cubes overlapping!"            
              #declare c=c+1;
              #declare cflag2=1;
           #else
              //#declare cflag=0;
              #declare c=0;
           #end
           #declare b=b+1;
        #end
        #if (cflag2=0)
          #declare cflag=0;
        #end


-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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