POV-Ray : Newsgroups : povray.general : Check if objects intersect Server Time
27 Nov 2024 12:35:16 EST (-0500)
  Check if objects intersect (Message 1 to 6 of 6)  
From: SharkD
Subject: Check if objects intersect
Date: 8 Nov 2008 20:50:00
Message: <web.4916415194a473741f7585b80@news.povray.org>
Is there a function that returns true if two objects intersect? Thanks!

-Mike


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: Check if objects intersect
Date: 8 Nov 2008 22:07:06
Message: <491653da@news.povray.org>
SharkD wrote:
> Is there a function that returns true if two objects intersect? Thanks!

I don't think that's technically possible to do with arbitrary objects...


Post a reply to this message

From: SharkD
Subject: Re: Check if objects intersect
Date: 9 Nov 2008 03:45:00
Message: <web.4916a1e7205550c9d79f8a540@news.povray.org>
Nicolas Alvarez <nic### [at] gmailcom> wrote:
> SharkD wrote:
> > Is there a function that returns true if two objects intersect? Thanks!
>
> I don't think that's technically possible to do with arbitrary objects...

That's too bad. It would be cool to be able to check whether an intersection is
empty or not.

-Mike


Post a reply to this message

From: Chris B
Subject: Re: Check if objects intersect
Date: 9 Nov 2008 04:16:47
Message: <4916aa7f$1@news.povray.org>
"SharkD" <nomail@nomail> wrote in message 
news:web.4916415194a473741f7585b80@news.povray.org...
> Is there a function that returns true if two objects intersect? Thanks!
>
> -Mike
>

I don't think there's any universally reliable way to do that.

In some circumstances you may be able to construct an approach using the 
min_extent and max_extent functions with the object you get by using an 
intersection of the two objects you're interested in to help determine this, 
but these functions use the bounding box of the resulting object and, as the 
help says: "this is not perfect, in some cases (such as CSG intersections 
and differences or isosurfaces) the bounding box does not represent the 
actual dimensions of the object".

Given this, you could (with a considerable degree of caution) construct a 
macro that may be able to serve your particular needs by combining the 
min_extent and max_extent functions and the trace function. If the extent 
values returned are very large (10000000000), then the objects don't 
intersect. If any of the dimensions is zero, then they don't intersect. 
Otherwise you'd need to fire a grid of lines through the space using the 
trace function to see if any hit the object. If any hit the intersection 
object, then it exists. If none hit the object it's still possible that the 
original objects intersected, but that your rays were'nt close enough 
together to hit it.

I've pasted in a bit of SDL below that may help if you wish to explore this 
approach.

Hope that helps.

Regards,
Chris B.


camera {location <0,0,-6> look_at 0}

light_source { <0,100,-10>, 1 }

#declare MyObject = intersection {
  sphere {y,1}
  sphere {-x,0.01}
  pigment {rgb 1}
}

#declare MyObject_Min = min_extent(MyObject);
#declare MyObject_Max = max_extent(MyObject);
#declare MyObject_Dim = MyObject_Max - MyObject_Min;

#debug concat(" Min extents: ",vstr(3,MyObject_Min,","3,3),"\n")
#debug concat(" Max extents: ",vstr(3,MyObject_Max,","3,3),"\n")
#debug concat(" Dimensions:  ",vstr(3,MyObject_Dim,","3,3),"\n")

#if (MyObject_Max.x>1000000)
  #debug "Clear Miss\n"
#end
#if (MyObject_Dim.x=0 | MyObject_Dim.y=0 | MyObject_Dim.z=0)
  #debug "Miss\n"
#end

// Otherwise use trace to test the object.

object {MyObject}


Post a reply to this message

From: SharkD
Subject: Re: Check if objects intersect
Date: 9 Nov 2008 05:25:00
Message: <web.4916b9eb205550c91da2db9f0@news.povray.org>
"Chris B" <nom### [at] nomailcom> wrote:
> In some circumstances you may be able to construct an approach using the
> min_extent and max_extent functions with the object you get by using an
> intersection of the two objects you're interested in to help determine this,
> but these functions use the bounding box of the resulting object and, as the
> help says: "this is not perfect, in some cases (such as CSG intersections
> and differences or isosurfaces) the bounding box does not represent the
> actual dimensions of the object".
>
> Given this, you could (with a considerable degree of caution) construct a
> macro that may be able to serve your particular needs by combining the
> min_extent and max_extent functions and the trace function. If the extent
> values returned are very large (10000000000), then the objects don't
> intersect. If any of the dimensions is zero, then they don't intersect.
> Otherwise you'd need to fire a grid of lines through the space using the
> trace function to see if any hit the object. If any hit the intersection
> object, then it exists. If none hit the object it's still possible that the
> original objects intersected, but that your rays were'nt close enough
> together to hit it.
>
> I've pasted in a bit of SDL below that may help if you wish to explore this
> approach.
>
> Hope that helps.
>
> Regards,
> Chris B.

Thank you very much for your excellent reply! I do not, however, want to go to
so much trouble at this time. I have decided that it is sufficient for my
purposes to approximate things by constructing "bounding spheres".

-Mike


Post a reply to this message

From: Tim Attwood
Subject: Re: Check if objects intersect
Date: 9 Nov 2008 17:33:09
Message: <49176525@news.povray.org>
>> In some circumstances you may be able to construct an approach using the
>> min_extent and max_extent functions with the object you get by using an
>> intersection of the two objects you're interested in to help determine 
>> this,
>> but these functions use the bounding box of the resulting object and, as 
>> the
>> help says: "this is not perfect, in some cases (such as CSG intersections
>> and differences or isosurfaces) the bounding box does not represent the
>> actual dimensions of the object".
>>
>> Given this, you could (with a considerable degree of caution) construct a
>> macro that may be able to serve your particular needs by combining the
>> min_extent and max_extent functions and the trace function. If the extent
>> values returned are very large (10000000000), then the objects don't
>> intersect. If any of the dimensions is zero, then they don't intersect.
>> Otherwise you'd need to fire a grid of lines through the space using the
>> trace function to see if any hit the object. If any hit the intersection
>> object, then it exists. If none hit the object it's still possible that 
>> the
>> original objects intersected, but that your rays were'nt close enough
>> together to hit it.
>>
>> I've pasted in a bit of SDL below that may help if you wish to explore 
>> this
>> approach.
>>
>> Hope that helps.
>>
>> Regards,
>> Chris B.
>
> Thank you very much for your excellent reply! I do not, however, want to 
> go to
> so much trouble at this time. I have decided that it is sufficient for my
> purposes to approximate things by constructing "bounding spheres".
>
> -Mike

I worked on this before...
this macro detects collisions of two objects.

It works by casting random rays at an intersection
some number of times.
While theoretically it could miss a collision, in
practice the sort of collisions it misses are
the sort of thing that are hard for the human eye
to see.

#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 cnt = 0;
      #while ((result = false) & (cnt < rez))
         #local Pt = VRand_In_Box(Mn, Mx, S1);
         #local Norm = <0,0,0>;
         #local Hit = trace(AB,<Pt.x,Mn.y-0.1,Pt.z>,y,Norm);
         #if (vlength(Norm)!=0)
            #local result = true;
         #else
            #local Hit = trace(AB,<Mn.x-0.1,Pt.y,Pt.z>,x,Norm);
            #if (vlength(Norm)!=0)
               #local result = true;
            #else
               #local Hit = trace(AB,<Pt.x,Pt.y,Mn.z-0.1,>,z,Norm);
               #if (vlength(Norm)!=0)
                  #local result = true;
               #end
            #end
         #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.085,0>
};

#local result = collision(sample1 sample2 1000);

object {sample1}
object {sample2}

union {
#switch (result)
   #case (0)
      text {ttf "tahoma.ttf" "Doesn't collide." 0.1,0}
   #break
   #case (1)
      text {ttf "tahoma.ttf" "Collides!" 0.1,0 }
   #break
#end
   scale <0.2,0.2,1>
   translate <-1,-0.5,-1>
   pigment {Orange}
}


Post a reply to this message

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