POV-Ray : Newsgroups : povray.tools.general : Problem with trace() - how to test for ray directions other than towards or= Server Time
28 Mar 2024 18:17:28 EDT (-0400)
  Problem with trace() - how to test for ray directions other than towards or= (Message 1 to 3 of 3)  
From: Yadgar
Subject: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 04:55:01
Message: <web.464eba4ca6148d97ac54333c0@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: Jaime Vives Piqueres
Subject: Re: Problem with trace() - how to test for ray directions other than towards or=
Date: 19 May 2007 05:39:41
Message: <464ec5dd$1@news.povray.org>
Yadgar wrote:
>     #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>;


  Looking at this code, I can't see how you would get any other result: you 
are tracing always from <0,20,0> to <0,-20,0>, so obviously the x and z 
coordinates of the intersection must be always 0. Or perhaps I didn't have 
enough coffee this morning? :)

I think moving around the terrain is a strange idea: you will be better 
moving around trvect.

Regards,

--
Jaime


Post a reply to this message

From: Alain
Subject: Re: Problem with trace() - how to test for ray directions other than towards or=
Date: 22 Jun 2009 14:51:03
Message: <4a3fd297@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
> 
> 
> 
> 
A few questions:
For your trace, why do you move the object instead of the origin point?
Remove:
#declare Terrain_Temporary=object { Terrain translate <-xpos, 0, -zpos>}

Change the trace to:
#declare pos=trace(Terrain, <xpos, 10, zpos>, -trvect)+<0, rad, 0>;
The y value is to ensure that you start tracing from above your object.

A word of warning: You should NEVER use lower case single character 
variables name. In fact, ALL user variable should start with an upper 
case letter, as all reserved names start with a lower case letter.

Alain


Post a reply to this message

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