POV-Ray : Newsgroups : povray.advanced-users : Limited line-of-sight test? Server Time
22 Dec 2024 16:07:19 EST (-0500)
  Limited line-of-sight test? (Message 1 to 7 of 7)  
From: Cousin Ricky
Subject: Limited line-of-sight test?
Date: 28 Jul 2015 22:41:32
Message: <55b83d5c@news.povray.org>
Is there some function or quick method of determining whether or not an 
object blocks the line-of-sight between two points?  The trace() 
function, on its own, is subject to false positives.  For example:

   #declare Obstacle = torus { 3, 1 }
   #declare Pt1 = <-1, 0, 0>;
   #declare Pt2 = <1, 0, 0>;
   #declare Test = <0, 0, 0>;
   trace (Obstacle, Pt1, Pt2 - Pt1, Test)

The torus does not block the line of sight between Pt1 and Pt2, but the 
trace() function isn't set up to make that distinction.

I have a rough idea for a solution in mind, but it is likely to be 
costly in parse time.  Is there already a built-in function that I've 
missed, or a fast solution to this problem?


Post a reply to this message

From: scott
Subject: Re: Limited line-of-sight test?
Date: 29 Jul 2015 02:49:34
Message: <55b8777e$1@news.povray.org>
> Is there some function or quick method of determining whether or not an
> object blocks the line-of-sight between two points?  The trace()
> function, on its own, is subject to false positives.  For example:
>
>    #declare Obstacle = torus { 3, 1 }
>    #declare Pt1 = <-1, 0, 0>;
>    #declare Pt2 = <1, 0, 0>;
>    #declare Test = <0, 0, 0>;
>    trace (Obstacle, Pt1, Pt2 - Pt1, Test)
>
> The torus does not block the line of sight between Pt1 and Pt2,

I think you'll find it does :-)


Post a reply to this message

From: MichaelJF
Subject: Re: Limited line-of-sight test?
Date: 29 Jul 2015 02:50:00
Message: <web.55b876ba67ef193326c1a48c0@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:
> Is there some function or quick method of determining whether or not an
> object blocks the line-of-sight between two points?  The trace()
> function, on its own, is subject to false positives.  For example:
>
>    #declare Obstacle = torus { 3, 1 }
>    #declare Pt1 = <-1, 0, 0>;
>    #declare Pt2 = <1, 0, 0>;
>    #declare Test = <0, 0, 0>;
>    trace (Obstacle, Pt1, Pt2 - Pt1, Test)
>
> The torus does not block the line of sight between Pt1 and Pt2, but the
> trace() function isn't set up to make that distinction.
>
> I have a rough idea for a solution in mind, but it is likely to be
> costly in parse time.  Is there already a built-in function that I've
> missed, or a fast solution to this problem?

I never learned of such a built-in function, but I think the following test will
not increase the parse time dramatically. Here your translated torus blocks the
sight.

   #declare Obstacle = torus { 3, 1 translate <-2,0,0>}
   #declare Pt1 = <-1, 0, 0>;
   #declare Pt2 = <1, 0, 0>;
   #declare TestDirection=Pt2-Pt1;
   #declare Test = <1, 0, 0>;
   #declare Hit=trace (Obstacle, Pt1, TestDirection, Test);


#declare ObstacleHit=false;
#if (vlength(Test)>0) // trace successful
   #if (vlength(TestDirection)>vlength(Hit-Pt1) )
      #declare ObstacleHit=true;
   #end
#end

Problems can arise if your starting point Pt1 is very close to the obstacle
since POV has a precision issue comparing floating point numbers.

Best regards,
MIchael


Post a reply to this message

From: Le Forgeron
Subject: Re: Limited line-of-sight test?
Date: 29 Jul 2015 03:16:31
Message: <55b87dcf$1@news.povray.org>
Le 29/07/2015 08:49, scott a écrit :
>> Is there some function or quick method of determining whether or not an
>> object blocks the line-of-sight between two points?  The trace()
>> function, on its own, is subject to false positives.  For example:
>>
>>    #declare Obstacle = torus { 3, 1 }
>>    #declare Pt1 = <-1, 0, 0>;
>>    #declare Pt2 = <1, 0, 0>;
>>    #declare Test = <0, 0, 0>;
>>    trace (Obstacle, Pt1, Pt2 - Pt1, Test)
>>
>> The torus does not block the line of sight between Pt1 and Pt2,
>
> I think you'll find it does :-)
>

1. it's the line of sight from Pt1 toward Pt2
2. trace report an intersection
3. if I'm correct, the intersection is after Pt2

internal clear area of Obstacle is -2 to 2 on X axis ( +/- 3 -/+ 1 )

You are both correct, it's only a matter of checking where is the result 
of trace in regards to the pt1/pt2 segment, or not.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Limited line-of-sight test?
Date: 31 Jul 2015 11:09:55
Message: <55bb8fc3$1@news.povray.org>
On 07/29/2015 02:46 AM, MichaelJF wrote:
> I never learned of such a built-in function, but I think the following test will
> not increase the parse time dramatically. [snip]
>
>     [snip]
>
> #declare ObstacleHit=false;
> #if (vlength(Test)>0) // trace successful
>     #if (vlength(TestDirection)>vlength(Hit-Pt1) )
>        #declare ObstacleHit=true;
>     #end
> #end

Thank you.  I was afraid to try anything involving vlength() because of 
the implicit square root calculation, but your idea turns out to be 
faster than the other ideas I tried.

It seems that the complexity of the SDL makes more of a difference than 
the complexity of the underlying calculation, at least in this case. 
This now has me wondering what an LR(k) parser would do for POV-Ray 
parse times.


Post a reply to this message

From: clipka
Subject: Re: Limited line-of-sight test?
Date: 31 Jul 2015 14:18:50
Message: <55bbbc0a$1@news.povray.org>
Am 31.07.2015 um 17:10 schrieb Cousin Ricky:

> It seems that the complexity of the SDL makes more of a difference than
> the complexity of the underlying calculation, at least in this case.

Absolutely. As a general rule of thumb, the number of tokens processed 
is the bottleneck, no matter what you do with SDL. (And remember that 
SDL is an entirely interpreted language; no compilation done at all, so 
tokens in loops are processed again and again and again.)

Unless you frequently call macros defined in a different source file. 
Such macro calls are even significantly more expensive.

For heavy math, functions can be a way out, as those are parsed only 
when defined.

> This now has me wondering what an LR(k) parser would do for POV-Ray
> parse times.

No need to dig deep into compiler theory - anything that's not a naive 
interpreter, but does /some/ level of compilation instead, would be a 
huge step forward ;)

POV-Ray's parser was fine as long as POV-Ray scene files were indeed 
just plain scene descriptions. But the approach has become inadequate 
ever since macros and loops were introduced.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Limited line-of-sight test?
Date: 9 Aug 2015 21:53:38
Message: <55c80422$1@news.povray.org>
On 31.07.2015 17:10, Cousin Ricky wrote:

> Thank you.  I was afraid to try anything involving vlength() because of
> the implicit square root calculation, but your idea turns out to be
> faster than the other ideas I tried.

Note if all you do is comparing lengths you don't need the square
root, you can compare the squared sums instead (vdot(v,v)), but of
course the extra tokens may already be more expensive.

Even more directly you can test if P1 and Hit are on the same
side of P2:

    #if (vdot(TestDirection,Pt2-Hit) >= 0)
      // Hit (Pt1->Pt2 same direction as Hit->Pt2)


Post a reply to this message

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