 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Is there a reasonably simple way in POV-Ray to produce a Boolean value
representing whether or no two objects intersect? As in...
#if ("object{Thing1} intersects object{Thing2}")
// STUFF TO DO IF THEY INTERSECT
#else
// STUFF TO DO IF THEY DON'T INTERSECT
#end
I would very much appreciate if some kind soul could point out the section
of the documentation and/or available resources that deal with this issue.
Thanks in advance.
Mike C.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Mike the Elder" <zer### [at] wyan org> wrote in message
news:web.44c51bba804fff24aaf01cad0@news.povray.org...
> Is there a reasonably simple way in POV-Ray to produce a Boolean value
> representing whether or no two objects intersect? As in...
>
> #if ("object{Thing1} intersects object{Thing2}")
> // STUFF TO DO IF THEY INTERSECT
> #else
> // STUFF TO DO IF THEY DON'T INTERSECT
> #end
>
> I would very much appreciate if some kind soul could point out the
section
> of the documentation and/or available resources that deal with this
issue.
For some simple objects, this could be done, but most of the time it
would be impossible to do accurately imho :-/
best you can do, is to check if the bounding boxes intersect
cu!
--
#macro G(b,e)b+(e-b)*C/50#end#macro _(b,e,k,l)#local C=0;#while(C<50)
sphere{G(b,e)+3*z.1pigment{rgb G(k,l)}finish{ambient 1}}#local C=C+1;
#end#end _(y-x,y,x,x+y)_(y,-x-y,x+y,y)_(-x-y,-y,y,y+z)_(-y,y,y+z,x+y)
_(0x+y.5+y/2x)_(0x-y.5+y/2x) // ZK http://www.povplace.com
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Mike the Elder" <zer### [at] wyan org> wrote:
> Is there a reasonably simple way in POV-Ray to produce a Boolean value
> representing whether or no two objects intersect? As in...
>
> #if ("object{Thing1} intersects object{Thing2}")
> // STUFF TO DO IF THEY INTERSECT
> #else
> // STUFF TO DO IF THEY DON'T INTERSECT
> #end
>
> I would very much appreciate if some kind soul could point out the section
> of the documentation and/or available resources that deal with this issue.
>
> Thanks in advance.
>
> Mike C.
I was interested in your problem and did a couple of quick tests. Testing
min_extent and max_extent on two spheres known to intersect produced
predictable results. When the spheres did not intersect, the results for
the intersection object were as follows.
min_extent = <-10000000000.000000,-10000000000.000000,-10000000000.000000>
max_extent = <10000000000.000000,10000000000.000000,10000000000.000000>
So it looks like this could be used as a test, although I don't really know
how robust it is.
Abe
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Mike the Elder" <zer### [at] wyan org> wrote:
> Is there a reasonably simple way in POV-Ray to produce a Boolean value
> representing whether or no two objects intersect? As in...
>
> #if ("object{Thing1} intersects object{Thing2}")
> // STUFF TO DO IF THEY INTERSECT
> #else
> // STUFF TO DO IF THEY DON'T INTERSECT
> #end
>
> I would very much appreciate if some kind soul could point out the section
> of the documentation and/or available resources that deal with this issue.
>
> Thanks in advance.
>
> Mike C.
Perhaps you can use CSG "intersect{}" and then chack min_extents,
max_extents.
Haver a look at this and see if you can get something to work out of it:
//START
global_settings {
max_trace_level 15
ambient_light 1
adc_bailout 0.0001
}
camera {
location <0,3,-5>
look_at 0
}
#declare LB=
sphere{0 50 hollow no_image
texture{pigment{rgb 1} finish{ambient 20}}
}
light_source{0 rgb 1
looks_like{LB}
fade_power 2 fade_distance 300
translate <0,100,-100>
}
#declare Obj1=sphere{<0,0,0> 1 pigment{rgb<1,0,0>}}
#declare Obj2=sphere{<-2.5,0,0> 1 pigment{rgb<0,1,0>}}
#declare Obj3=sphere{<1.5,0,0> 1 pigment{rgb<0,0,1>}}
object{Obj1}
object{Obj2}
object{Obj3}
#declare Int12=intersection{object{Obj1}object{Obj2}}
#declare Int13=intersection{object{Obj1}object{Obj3}}
#declare Siz12=vlength(min_extent(Int12)-max_extent(Int12));
#declare Siz13=vlength(min_extent(Int13)-max_extent(Int13));
text {ttf "arial.ttf",str(Siz12,0,3),0.1,0 scale 1/3 translate <-2.5,1.5,0>
pigment{rgb 1}}
text {ttf "arial.ttf",str(Siz13,0,3),0.1,0 scale 1/3 translate <1.5,1.5,0>
pigment{rgb 1}}
//END
-tgq
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Wasn't it Abe who wrote:
>"Mike the Elder" <zer### [at] wyan org> wrote:
>> Is there a reasonably simple way in POV-Ray to produce a Boolean value
>> representing whether or no two objects intersect? As in...
>>
>> #if ("object{Thing1} intersects object{Thing2}")
>> // STUFF TO DO IF THEY INTERSECT
>> #else
>> // STUFF TO DO IF THEY DON'T INTERSECT
>> #end
>>
>> I would very much appreciate if some kind soul could point out the section
>> of the documentation and/or available resources that deal with this issue.
>>
>> Thanks in advance.
>>
>> Mike C.
>
>I was interested in your problem and did a couple of quick tests. Testing
>min_extent and max_extent on two spheres known to intersect produced
>predictable results. When the spheres did not intersect, the results for
>the intersection object were as follows.
>
>min_extent = <-10000000000.000000,-10000000000.000000,-10000000000.000000>
>max_extent = <10000000000.000000,10000000000.000000,10000000000.000000>
>
>So it looks like this could be used as a test, although I don't really know
>how robust it is.
POV calculates the intersection of the bounding boxes (because it can
calculate that) and uses that as the bounding box for the intersection
(which would be next to impossible to calculate in the general case).
If you consider these non-intersecting spheres
intersection {
sphere {0,1}
sphere {0,1 translate <1.2,1.2,1.2>}
pigment {rgb x}
}
Their bounding boxes do intersect at the corner, like this
intersection {
box{-1,1}
box {-1,1 translate <1.2,1.2,1.2>}
pigment {rgb x}
}
So that method would be wrong in suggesting that the spheres
intersected.
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Mike the Elder wrote:
> Is there a reasonably simple way in POV-Ray to produce a Boolean value
> representing whether or no two objects intersect?
Don't pay too much attention to the other answers because in the
generic case what you ask is just not possible (not even in theory,
at least not in a reasonable time with perfect accuracy).
You could use a *really* slow method of sampling points inside the
bounding box of one of the objects and seeing if a point is inside
both objects, but this would be very slow and quite inaccurate (you
could, of course, increase accuracy by taking more samples, but there
would still be a margin of error and the amount of time required
probably grows by the power of 3).
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Mike Williams <nos### [at] econym demon co uk> wrote:
> Wasn't it Abe who wrote:
> >"Mike the Elder" <zer### [at] wyan org> wrote:
> >> Is there a reasonably simple way in POV-Ray to produce a Boolean value
> >> representing whether or no two objects intersect? As in...
> >>
> >> #if ("object{Thing1} intersects object{Thing2}")
> >> // STUFF TO DO IF THEY INTERSECT
> >> #else
> >> // STUFF TO DO IF THEY DON'T INTERSECT
> >> #end
> >>
> >> I would very much appreciate if some kind soul could point out the section
> >> of the documentation and/or available resources that deal with this issue.
> >>
> >> Thanks in advance.
> >>
> >> Mike C.
> >
> >I was interested in your problem and did a couple of quick tests. Testing
> >min_extent and max_extent on two spheres known to intersect produced
> >predictable results. When the spheres did not intersect, the results for
> >the intersection object were as follows.
> >
> >min_extent = <-10000000000.000000,-10000000000.000000,-10000000000.000000>
> >max_extent = <10000000000.000000,10000000000.000000,10000000000.000000>
> >
> >So it looks like this could be used as a test, although I don't really know
> >how robust it is.
>
> POV calculates the intersection of the bounding boxes (because it can
> calculate that) and uses that as the bounding box for the intersection
> (which would be next to impossible to calculate in the general case).
>
> If you consider these non-intersecting spheres
> intersection {
> sphere {0,1}
> sphere {0,1 translate <1.2,1.2,1.2>}
> pigment {rgb x}
> }
>
> Their bounding boxes do intersect at the corner, like this
> intersection {
> box{-1,1}
> box {-1,1 translate <1.2,1.2,1.2>}
> pigment {rgb x}
> }
>
> So that method would be wrong in suggesting that the spheres
> intersected.
>
> --
> Mike Williams
> Gentleman of Leisure
Ha! An inconvenient exception. I think I'll choose to ignore it.
[retreats into own mental bounding box]
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
well , from what i have see
Povray uses a default value min_extent() of -1 , if the object exists or not
, and use a default value max_extent() of 1 if the object exist or not
then if i use this
#local U=intersection { box {0,1} box {2,3}}
and
#local U2= object {U scale 1000}
if the object U doesnt exists then we will always have
[max_entent(U2) - max_entent(U) ].x = 0 and
[max_entent(U2) - max_entent(U) ].y = 0 and
[max_entent(U2) - max_entent(U) ].z = 0
and
[min_entent(U2) - min_entent(U)].x =0 and
[min_entent(U2) - min_entent(U)].x =0 and
[min_entent(U2) - min_entent(U)].x =0
In brief ..scaling a non existing object will give the same min_extend value
and max_extend value that the non-scaled object .. if not then the object
always exists ..
"Warp" <war### [at] tag povray org> a écrit dans le message de
news:44c54897$1@news.povray.org...
> Mike the Elder wrote:
> > Is there a reasonably simple way in POV-Ray to produce a Boolean value
> > representing whether or no two objects intersect?
>
> Don't pay too much attention to the other answers because in the
> generic case what you ask is just not possible (not even in theory,
> at least not in a reasonable time with perfect accuracy).
>
> You could use a *really* slow method of sampling points inside the
> bounding box of one of the objects and seeing if a point is inside
> both objects, but this would be very slow and quite inaccurate (you
> could, of course, increase accuracy by taking more samples, but there
> would still be a margin of error and the amount of time required
> probably grows by the power of 3).
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"NEWS" <pen### [at] caramail fr> wrote in message
news:44c5fa0f$1@news.povray.org...
> well , from what i have see
>
> Povray uses a default value min_extent() of -1 , if the object exists or
> not
> , and use a default value max_extent() of 1 if the object exist or not
>
> then if i use this
> #local U=intersection { box {0,1} box {2,3}}
>
> and
>
> #local U2= object {U scale 1000}
>
> if the object U doesnt exists then we will always have
>
> [max_entent(U2) - max_entent(U) ].x = 0 and
> [max_entent(U2) - max_entent(U) ].y = 0 and
> [max_entent(U2) - max_entent(U) ].z = 0
>
> and
>
>
> [min_entent(U2) - min_entent(U)].x =0 and
> [min_entent(U2) - min_entent(U)].x =0 and
> [min_entent(U2) - min_entent(U)].x =0
>
>
>
>
> In brief ..scaling a non existing object will give the same min_extend
> value
> and max_extend value that the non-scaled object .. if not then the object
> always exists ..
>
>
Fine for boxes only. anything else will test wrong. The corners of two
sphere's bounding boxes could intersect without the sphere's intersecting
each other at all. May be it's possible to test it by using the mathematical
formula for each object instead - I'm not sure.
--
-Nekar Xenos
"The truth is out there"
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
i think you must read again ...
i check the bounding of the intersection ... and not the intersection of 2
bounding ...
"Nekar" <ger### [at] rpmmag co za> a écrit dans le message de
news:44c60af5@news.povray.org...
>
> "NEWS" <pen### [at] caramail fr> wrote in message
> news:44c5fa0f$1@news.povray.org...
> > well , from what i have see
> >
> > Povray uses a default value min_extent() of -1 , if the object exists or
> > not
> > , and use a default value max_extent() of 1 if the object exist or not
> >
> > then if i use this
> > #local U=intersection { box {0,1} box {2,3}}
> >
> > and
> >
> > #local U2= object {U scale 1000}
> >
> > if the object U doesnt exists then we will always have
> >
> > [max_entent(U2) - max_entent(U) ].x = 0 and
> > [max_entent(U2) - max_entent(U) ].y = 0 and
> > [max_entent(U2) - max_entent(U) ].z = 0
> >
> > and
> >
> >
> > [min_entent(U2) - min_entent(U)].x =0 and
> > [min_entent(U2) - min_entent(U)].x =0 and
> > [min_entent(U2) - min_entent(U)].x =0
> >
> >
> >
> >
> > In brief ..scaling a non existing object will give the same min_extend
> > value
> > and max_extend value that the non-scaled object .. if not then the
object
> > always exists ..
> >
> >
> Fine for boxes only. anything else will test wrong. The corners of two
> sphere's bounding boxes could intersect without the sphere's intersecting
> each other at all. May be it's possible to test it by using the
mathematical
> formula for each object instead - I'm not sure.
>
>
> --
> -Nekar Xenos
> "The truth is out there"
>
>
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Wasn't it NEWS who wrote:
>i think you must read again ...
>
>i check the bounding of the intersection ... and not the intersection of 2
>bounding ...
I think you missed this bit from earlier in the thread:
POV calculates the intersection of the bounding boxes (because it can
calculate that) and uses that as the bounding box for the intersection
(which would be next to impossible to calculate in the general case).
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
NEWS wrote:
> i check the bounding of the intersection ... and not the intersection of 2
> bounding ...
That doesn't tell whether the objects are intersecting or not,
only if their bounding boxes are.
There's no reasonable way for POV-Ray to tell for sure if two
objects are intersecting or not.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp <war### [at] tag povray org> wrote:
> NEWS wrote:
> > i check the bounding of the intersection ... and not the intersection of 2
> > bounding ...
>
> That doesn't tell whether the objects are intersecting or not,
> only if their bounding boxes are.
>
> There's no reasonable way for POV-Ray to tell for sure if two
> objects are intersecting or not.
What's the disadvantage of what I suggested? Instead of checking for the
intersecting of bounding boxes, check the min and max extents of a CSG
intersection. The only odd part is when I test it, when there is no
intersection, the min-max is not zero, but a very large number, but this
should still be usable, basically check the min-max of a CSG intersection
vs the min-max of a CSG union.
-tgq
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
> There's no reasonable way for POV-Ray to tell for sure if two
> objects are intersecting or not.
Ah, but there are always the unreasonably cumbersome ways to know whether it
is likely.... You can also render that CSG difference scaled to fit the
screen and have your pet monkey tell you whether it sees any color.... Or
you could make use of a trace, or feed the above rendering back in and use
eval_pigment instead of the monkey.
Who needs "reasonable"? :)
Charles
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Thanks to all who tried to help. If I come up with anything that works
fairly well,I will certainly post it.
To Charles: Sadly, my monkey is not availble to assist. He was busy trying
to type out "Hamlet" and got as far as "... To be or not to be; that is the
qestibjdkjnmksyg..." when he threw up is arms in disgust and walked off to
get drunk with an infinite number of chums.
Best wishes to all,
-Mike C.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
"Trevor G Quayle" <Tin### [at] hotmail com> wrote:
> Warp <war### [at] tag povray org> wrote:
> > NEWS wrote:
> > > i check the bounding of the intersection ... and not the intersection of 2
> > > bounding ...
> >
> > That doesn't tell whether the objects are intersecting or not,
> > only if their bounding boxes are.
> >
> > There's no reasonable way for POV-Ray to tell for sure if two
> > objects are intersecting or not.
>
> What's the disadvantage of what I suggested? Instead of checking for the
> intersecting of bounding boxes, check the min and max extents of a CSG
> intersection. The only odd part is when I test it, when there is no
> intersection, the min-max is not zero, but a very large number, but this
> should still be usable, basically check the min-max of a CSG intersection
> vs the min-max of a CSG union.
>
> -tgq
ok, I did some more testing and it doesn't always work, I guess I just got
lucky with the first couple tests I tried...
-tgq
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Testing the min_extent (or max_extent) of the intesetion of the two objects
seems to work pretty well.
In the example below, "TheBox" will intersect "TheSphere" iff "SphereRadius"
has a magnitude of 1 or more.
===============================================
#declare SphereRadius = 1; //Just big enough
#declare TheBox = box{<1,1,1>,<-1,-1,-1>}
#declare TheSphere = sphere{<2,0,0>,SphereRadius}
#declare TestThing = intersection{object{TheBox} object{TheSphere}}
#if (min_extent(TestThing).x > -1000000)
#warning "Yes, they intersect."
#else
#warning "No, they do not intersect."
#end
===============================================
produces: "Parse Warning: Yes, they intersect."
AND
===============================================
#declare SphereRadius = .999999; //Just too small
#declare TheBox = box{<1,1,1>,<-1,-1,-1>}
#declare TheSphere = sphere{<2,0,0>,SphereRadius}
#declare TestThing = intersection{object{TheBox} object{TheSphere}}
#if (min_extent(TestThing).x > -1000000)
#warning "Yes, they intersect."
#else
#warning "No, they do not intersect."
#end
===============================================
produces: "Parse Warning: No, they do not intersect."
In a further experiment, where one of the test objects was a slightly more
complex object (a union of several spheres) the results remained
consistent. This method seems quite sufficient for my purpose. (Which, by
the way, is filling a box with "packing peanuts" turned every which way so
that no two "peanuts" will occupy the same space.)
Thanks again to all who contributed.
-Mike C.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Mike the Elder wrote:
> Testing the min_extent (or max_extent) of the intesetion of the two objects
> seems to work pretty well.
It works pretty well if it's enough to see if the bounding boxes
of the objects intersect.
However, bounding box is not the same as the object. In some cases
the bounding boxes may intersect but the objects don't.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Mike the Elder wrote:
> To Charles: Sadly, my monkey is not availble to assist. He was busy trying
> to type out "Hamlet" and got as far as "... To be or not to be; that is the
> qestibjdkjnmksyg..." when he threw up is arms in disgust and walked off to
> get drunk with an infinite number of chums.
And to meet up with Bob Newhart, I suppose?? ;-)
-=- Larry -=-
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp <war### [at] tag povray org> wrote:
> Mike the Elder wrote:
> > Testing the min_extent (or max_extent) of the intesetion of the two objects
> > seems to work pretty well.
>
> It works pretty well if it's enough to see if the bounding boxes
> of the objects intersect.
> However, bounding box is not the same as the object. In some cases
> the bounding boxes may intersect but the objects don't.
Warp is, of course, correct about this. Two shperes of radius 1 located at
<-1,-1,-1> and <1,1,1> read incorrectly as intersecting when it is just
their bounding boxes that touch. For the "packing peanut" problem,
however, the min_extent test method, combined with some fudged tolerances
for moving each new "peanut" just a bit past the first point of positive
itersection testing SHOULD (I hope) provide a way of piling up a bunch of
them in a more efficient manner than placing hundres of them individually.
Designing the individual "peanut" in such a way that it mostly fills a box
sould also help.
Best Wishes All,
- MIke C.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
> 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
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |