     POV-Ray : Newsgroups : povray.general : How to check if two objects have any intersection? Server Time: 30 Mar 2020 14:27:35 GMT  How to check if two objects have any intersection? (Message 1 to 4 of 4)          From: Kima Subject: How to check if two objects have any intersection? Date: 30 Jan 2020 21:10:00 Message:    ```I need an if statement to check if two objects have any intersection. I assumed
trace(a, b) should give false when there is no intersection, something like

#if ( trace(a,b) )
....
#else
....
#end

but apparently, trace return a vector, when if statement needs a numeric
expression.

How can I check if two objects have any overlap in an if statement?
```    From: jr Subject: Re: How to check if two objects have any intersection? Date: 30 Jan 2020 21:55:00 Message:    ```hi,

"Kima" <nomail@nomail> wrote:
> I need an if statement to check if two objects have any intersection. I assumed
> trace(a, b) should give false when there is no intersection, something like
>
>  #if ( trace(a,b) )
>    ....
>  #else
>    ....
>  #end
>
> but apparently, trace return a vector, when if statement needs a numeric
> expression.
>
> How can I check if two objects have any overlap in an if statement?

I guess you'd need to write a macro which takes the two objects and returns a
bool, true if the bounding boxes overlap (or whichever method you use to
determine "intersection").

regards, jr.
```    From: Bald Eagle Subject: Re: How to check if two objects have any intersection? Date: 30 Jan 2020 22:40:00 Message:    ```"Kima" <nomail@nomail> wrote:

> but apparently, trace return a vector, when if statement needs a numeric
> expression.

Well, since trace {} returns <0, 0, 0> as the surface normal if it misses the
object, then you can just add together the x, y, and z components of the vector
to give a scalar value.  Use abs() so nothing cancels out.

#declare TraceBool = abs(Normal.x)+abs(Normal.y)+abs(Normal.z);

Gonna be tricky with CSG to look at the right place and get an accurate result.
If they are curves / algebraic surfaces, then I might see about doing the math
to see if there are any intersection points.

Just curious - what if you did:
intersection {
ObjectA
ObjectB
}
and computed the volume of the bounding box?

At the very least, if you're "scanning" with trace{}, then it would give you a
much smaller, and accurate volume to focus on.
```    From: Alain Martel Subject: Re: How to check if two objects have any intersection? Date: 31 Jan 2020 17:01:23 Message: <5e345d63\$1@news.povray.org>    ```Le 2020-01-30 Ã  17:35, Bald Eagle a Ã©critÂ :
>
> "Kima" <nomail@nomail> wrote:
>
>> but apparently, trace return a vector, when if statement needs a numeric
>> expression.
>
> Well, since trace {} returns <0, 0, 0> as the surface normal if it misses the
> object, then you can just add together the x, y, and z components of the vector
> to give a scalar value.  Use abs() so nothing cancels out.
>
> #declare TraceBool = abs(Normal.x)+abs(Normal.y)+abs(Normal.z);
>
>
>
> Gonna be tricky with CSG to look at the right place and get an accurate result.
> If they are curves / algebraic surfaces, then I might see about doing the math
> to see if there are any intersection points.
>
> Just curious - what if you did:
> intersection {
>       ObjectA
>       ObjectB
> }
> and computed the volume of the bounding box?
>
> At the very least, if you're "scanning" with trace{}, then it would give you a
> much smaller, and accurate volume to focus on.
>
>

You can test for the length of the normal vector.
If the trace encounter a surface, the length is 1. If it miss, the
length is zero.

So, it become :
#declare TraceBool = vlength(Normal);
```        