POV-Ray : Newsgroups : povray.newusers : Trace function for dummies? [POVray version 3.6.2] : Re: Trace function for dummies? [POVray version 3.6.2] Server Time
5 Oct 2024 15:54:09 EDT (-0400)
  Re: Trace function for dummies? [POVray version 3.6.2]  
From: Warp
Date: 15 Sep 2009 16:14:25
Message: <4aaff5a1@news.povray.org>
Amazon_warrior <nomail@nomail> wrote:
> If someone could break down (preferably in words of one syllable!) the component
> parts of the trace function; such as the purpose, suggested parameters, what's
> essential and what's not, etc., I would be embarassingly grateful!

  The first parameter to the trace() function is, rather obviously, the
object being traced. Thus you have to #declare an object, and then use this
#declared identifier as the first parameter.

  The second parameter specifies the starting point of the ray to be traced.
Normally this starting point should be somewhere outside the object, at the
direction from which the ray should be traced. For example, if your object
was a sphere of radius 1 located at the origin, and you wanted to trace a
ray directly from above, the starting point of this ray could be, for example,
<0, 2, 0> (or anything else above <0, 1, 0>).
  The exact location of the starting point depends on what is it exactly
that you want to do. You'll have to figure out that first (ie. what is it
exactly that you want to do) before you can come up with the starting points.

  The third parameter specifies the direction towards which the ray should
be traced. This is a direction vector, not a point in space. Thus, in the
example above, if you want to trace the ray directly downwards, this parameter
would be <0, -1, 0> (ie. a vector pointing towards the negative y axis).
As this is a direction vector, it doesn't matter what the starting point is,
the ray will always be traced directly downwards from that starting point.

  The fourth parameter, if specified, should be the name of a vector
identifier. The normal vector of the object being traced at the intersection
point will be stored there. This normal vector can be useful for many things
(such as reorienting objects so that they are perpendicular to the surface
of the traced object). Most importantly, this normal vector can be used to
determine whether the ray hit the object or not. If the length of the
normal vector is 0, then the traced ray did not hit the object (you can
check this by using the vlength() function).

  trace() returns the hit point, or <0,0,0> if the object was not hit
(as mentioned, the only way to make sure whether it hit the object or not
is to check the normal vector; it's possible for the hit point to be
exactly at <0,0,0>, so the checking has to be done with the normal vector).

-- 
                                                          - Warp


Post a reply to this message

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