POV-Ray : Newsgroups : povray.general : Problem with trace() - how to test for ray directions other than towards or= Server Time
28 Nov 2024 08:53:45 EST (-0500)
  Problem with trace() - how to test for ray directions other than towards or= (Message 1 to 4 of 4)  
From: Yadgar
Subject: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 05:40:01
Message: <web.464ec550a6148d97cd5f50d20@news.povray.org>
High!

I want to place objects randomly on an isosurface; as the isosurface lies
perpendicular to the y axis, I tested for directions parallel to the y axis
rather  than pointing towards <0, 0, 0>.

But obviously all these rays missed - in a #warning output line, I always
get 0.00000 for the x and z components of trace(). What went wrong? Is it
in fact impossible, as the manual suggests, to safely test for
intersections other than
(Object, start_vector, -start_vector)? I even defined an auxiliary object
and translated it so that the starting point is exactly above the origin,
but this also failed...

Here are the relevant parts of the scene:

#declare Terrain_Part1_Function=
function
{
  pattern
  {
    granite
    scale 10
    poly_wave 0.333
  }
}
#declare Terrain_Part2_Function=
function
{
  pattern
  {
    bozo
    turbulence 2
    octaves 5
  }
}

#declare Terrain_Function=
function
{
  y + Terrain_Part1_Function(x, 0, z)
    + Terrain_Part2_Function(x, y, z)*0.0004
}

#declare Terrain=
isosurface
{
  function { Terrain_Function(x, y, z) }
  contained_by
  {
    box { -10, 10 }
  }
  max_gradient 3
  accuracy 0.0001
  #if (!map)
    texture { T_Sand }
  #else
    // texture { T_Physical_Map scale 2 }
  #end
}

#declare r1=seed(1584);
#declare r2=seed(2953);
#declare r3=seed(5930);
#declare r4=seed(8634);

#declare Ball=
sphere
{
  0, 1
}

object { Terrain }

#declare s=<4, 20, 5>;
#declare a=<4, -20, 5>;

#declare pos=trace(Terrain, s, a)+<0, 0.0017, 0>;


#if (!map)
  #if (ground=1)
    camera
    {
      location pos
      look_at pos+<0, sin((-90+(clock*0.5))*(pi/180)),
sin(clock*0.5*(pi/180))>
      angle 40
    }
  #else
    camera
    {
      location <15, 8, -15>
      look_at 0
      angle 40
    }
  #end
#else
  camera
  {
    orthographic
    location <0, 50, 0>
    look_at 0
    angle 40
  }
#end

#if (balls=1)
  #declare a=0;
  #while (a<1000)
    #declare xpos=rand(r1)*20-10;
    #declare zpos=rand(r2)*20-10;
    #declare Terrain_Temporary=
    object { Terrain translate <-xpos, 0, -zpos> }
    #declare trvect=<0, 20, 0>;
    #declare rad=0.01+rand(r3)/100*9;
    #declare pos=trace(Terrain_Temporary, trvect, -trvect)+<0, rad, 0>;
    #warning concat("<", str(pos.x, 2, -1), ", ", str(pos.y, 2, -1), ", "
str(pos.z, 2, -1), ">")
    object
    {
      Ball
      scale rad
      translate pos
      texture
      {
        pigment
        {
          color rgb <1, 0, 0>
        }
        finish
        {
          ambient 0.1
          diffuse 0.9
          brilliance 0.7
          phong 150
          phong_size 0.5
          reflection 0.6
          metallic
        }
      }
    }
    #declare a=a+1;
  #end
#end

See you on www.khyberspace.de !

Yadgar

Now playing: my loved one on his Ensoniq synthesizer


Post a reply to this message

From: Zeger Knaepen
Subject: Re: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 06:00:18
Message: <464ecab2$1@news.povray.org>
"Yadgar" <yaz### [at] gmxde> wrote in message
news:web.464ec550a6148d97cd5f50d20@news.povray.org...
> #declare s=<4, 20, 5>;
> #declare a=<4, -20, 5>;
>
> #declare pos=trace(Terrain, s, a)+<0, 0.0017, 0>;

I think you mean:
#declare pos=trace(Terrain,s,-y)+y*.0017;


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

From: Thomas de Groot
Subject: Re: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 09:42:50
Message: <464efeda$1@news.povray.org>
"Yadgar" <yaz### [at] gmxde> schreef in bericht 
news:web.464ec550a6148d97cd5f50d20@news.povray.org...
> High!
>
> I want to place objects randomly on an isosurface; as the isosurface lies
> perpendicular to the y axis, I tested for directions parallel to the y 
> axis
> rather  than pointing towards <0, 0, 0>.
>
> But obviously all these rays missed - in a #warning output line, I always
> get 0.00000 for the x and z components of trace(). What went wrong? Is it
> in fact impossible, as the manual suggests, to safely test for
> intersections other than
> (Object, start_vector, -start_vector)? I even defined an auxiliary object
> and translated it so that the starting point is exactly above the origin,
> but this also failed...
>

example:
#declare Norm = <0, 0, 0>;
#declare Start = <x-pos, 20, z-pos>;

testing for an intersection on a surface perpendicular to y, would be 
written as:
#declare Inter=
  trace ( MySphere, Start, -y, Norm );
  etc....
  )

That is how I do it.

Thomas


Post a reply to this message

From: Tim Attwood
Subject: Re: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 17:04:15
Message: <464f664f$1@news.povray.org>
> example:
> #declare Norm = <0, 0, 0>;
> #declare Start = <x-pos, 20, z-pos>;
>
> testing for an intersection on a surface perpendicular to y, would be 
> written as:
> #declare Inter=
>  trace ( MySphere, Start, -y, Norm );
>  etc....
>  )
>
> That is how I do it.
>
> Thomas

Also, if you want to test for a missed ray you should test the
normal for zero length.

#if (vlength(Norm)=0)
   //missed
#else
   //hit
#end


Post a reply to this message

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