POV-Ray : Newsgroups : povray.advanced-users : Use Slope pattern for Planting distribution? : Re: Use Slope pattern for Planting distribution? Server Time
6 Oct 2024 14:03:18 EDT (-0400)
  Re: Use Slope pattern for Planting distribution?  
From: Warp
Date: 12 Dec 2006 11:32:21
Message: <457ed993@news.povray.org>
Kirk Andrews <kir### [at] hotmailcom> wrote:
> Honestly, I've had a lot of difficulty understanding exactly how that works.
>  When you use the trace command to return the "normal", what exactly is
> being returned?  And perhaps someone might provide a short example code of
> how I might use that?

  Some basic vector math knowledge could be of great help when designing
thing with POV-Ray... :P

  A normal vector is a vector perpendicular (ie. at 90 degrees) to the
surface. In layman terms, a normal is a vector which points directly
away from the surface at that intersection point.

  You can use this normal vector to calculate the steepness of the surface
at that point.
  One simple way of doing this is using the dot product (vdot() function
in povray): Assuming that 'y' is up in your terrain and the normal vector
is normalized (ie. its length is 1; this can be done with vnormalize() just
in case), then the dot product of the normal vector and 'y' will give the
cosine of the angle between these two vectors. In other words, if the normal
vector has the same direction as 'y', the result of the dot product will
be 1 and if the normal vector is perpendicular to 'y' (ie. at 90 degrees)
then the result will be 0. Other directions of the normal vector will give
values in between 0 and 1 (not linearly, though, but that doesn't matter).

  In other words, if you do this:

#declare VD = vdot(vnormalize(TheNormalVectorYouGotWithTrace), y);

now VD will have a value between 0 and 1. 1 means completely vertical,
0 means completely horizontal. If you want to avoid putting a plant on
a surface which is too steep, try doing so only when VD > 0.2 or so
(try different values until you are happy).

  If you know the exact angle which you want to be the limit, then you
can simply compare VD with cos(radians(TheAngle)).

-- 
                                                          - Warp


Post a reply to this message

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