POV-Ray : Newsgroups : povray.advanced-users : Limited line-of-sight test? : Re: Limited line-of-sight test? Server Time
15 May 2024 19:35:08 EDT (-0400)
  Re: Limited line-of-sight test?  
From: MichaelJF
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

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