POV-Ray : Newsgroups : povray.advanced-users : Use Slope pattern for Planting distribution? Server Time
31 Oct 2024 12:16:30 EDT (-0400)
  Use Slope pattern for Planting distribution? (Message 1 to 10 of 25)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Kirk Andrews
Subject: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 08:50:00
Message: <web.457eb359aa33b1599033e1160@news.povray.org>
I'm trying to use the trace command to plant grass on my Isosurface
landscape, but I don't want it to "grow" on steep grades.  Is it possible
to use the slope pattern to control my distribution, or is there another
way to do this?

Thanks.


Post a reply to this message

From: Rune
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 09:24:58
Message: <457ebbba$1@news.povray.org>
Kirk Andrews wrote:
> I'm trying to use the trace command to plant grass on my Isosurface
> landscape, but I don't want it to "grow" on steep grades.  Is it
> possible to use the slope pattern to control my distribution, or is
> there another way to do this?

You can't use the slope pattern for this, but the trace function can return 
a normal vector which you can evaluate directly, for example by using the 
y-component of the normal vector.

Rune
-- 
http://runevision.com


Post a reply to this message

From: Kirk Andrews
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 09:35:01
Message: <web.457ebdbcdc80ee109033e1160@news.povray.org>
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?



"Rune" <new### [at] runevisioncom> wrote:
> Kirk Andrews wrote:
> > I'm trying to use the trace command to plant grass on my Isosurface
> > landscape, but I don't want it to "grow" on steep grades.  Is it
> > possible to use the slope pattern to control my distribution, or is
> > there another way to do this?
>
> You can't use the slope pattern for this, but the trace function can return
> a normal vector which you can evaluate directly, for example by using the
> y-component of the normal vector.
>
> Rune
> --
> http://runevision.com


Post a reply to this message

From: Warp
Subject: Re: Use Slope pattern for Planting distribution?
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

From: Kirk Andrews
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 12:25:00
Message: <web.457ee583dc80ee109033e1160@news.povray.org>
Thank you, that was very helpful--

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

In my defence, I am relatively new and to me, a "vector" is a *direction*
(which could be defined in various ways).  Yet what is returned is
obviously three float values combined in what POV calls a "vector".

Therefore, the normal vector could define a point 1 unit (or more?) away
from the intersected point in the perpendicular direction, or could be that
point minus the intersected point.  So I suppose my real question is: How
exactly does POV define its vectors?

In any case, you've certainly answered my current problem and I appreciate
your patience with my ignorance.

Kirk


Post a reply to this message

From: Tim Attwood
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 16:44:21
Message: <457f22b5$1@news.povray.org>
>>   Some basic vector math knowledge could be of great help when designing
>> thing with POV-Ray... :P
>
> In my defence, I am relatively new and to me, a "vector" is a *direction*
> (which could be defined in various ways).  Yet what is returned is
> obviously three float values combined in what POV calls a "vector".
>
> Therefore, the normal vector could define a point 1 unit (or more?) away
> from the intersected point in the perpendicular direction, or could be 
> that
> point minus the intersected point.  So I suppose my real question is: How
> exactly does POV define its vectors?

In POV vectors are directions from the origin. This can be used to represent
a point <x,y,z> by the magnitude of the vector, or in some cases the 
magnitude
is ignored and the vector only represents a direction. For example, the 
normal
returned from the trace function represents the direction of the vector 
perpendicular
to the surface as a unit vector from the origin. (A unit vector has a length 
of 1 unit)
The vnormalize function returns a unit vector from a non-unit vector by 
changing the
vector length to one without changing the direction. Essentially, POV uses 
vectors
to represent points, because points ARE vectors, but uses unit vectors for 
directions.

To complicate matters a bit more, POV also uses vectors to define colors, so 
there
are options for two more vector components filter and transmit, making a 5D 
vector.
For clarity of use the dot x, dot y, and dot z accessors can be used as dot 
red,
dot green, and dot blue; so N.x = N.red, N.y = N.green, and N.z = N.blue.
The other 2 components can be accessed with dot filter, and dot transmit.

Addtionally you can use dot u and dot v for 2D vectors. So N.x = N.u, and
N.y = N.v. Also 4D vectors <x,y,z,t>, where N.t = N.filter.


Post a reply to this message

From: Alain
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 16:53:25
Message: <457f24d5@news.povray.org>
Kirk Andrews nous apporta ses lumieres en ce 12-12-2006 12:23:
> Thank you, that was very helpful--

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

> In my defence, I am relatively new and to me, a "vector" is a *direction*
> (which could be defined in various ways).  Yet what is returned is
> obviously three float values combined in what POV calls a "vector".

> Therefore, the normal vector could define a point 1 unit (or more?) away
> from the intersected point in the perpendicular direction, or could be that
> point minus the intersected point.  So I suppose my real question is: How
> exactly does POV define its vectors?

> In any case, you've certainly answered my current problem and I appreciate
> your patience with my ignorance.

> Kirk

In fact, a vertor is a direction PLUS a distance. It can be defined as 3 angles 
and a distance, OR as the end point's coordinates relative to it's starting point.
In 2D, it's an angle plus a lenght or the 2D coordinates of the tip relative to 
the start.
A normalised vector is a vector witch is 1 unit in lenght. Normaly, the normal 
vector returned by the trace function is such a vector.

-- 
Alain
-------------------------------------------------
Make yourself a better person and know who you are before you try and know 
someone else and expect them to know you.


Post a reply to this message

From: Darren New
Subject: Re: Use Slope pattern for Planting distribution?
Date: 12 Dec 2006 17:04:16
Message: <457f2760$1@news.povray.org>
Alain wrote:
> In fact, a vertor is a direction PLUS a distance.

Technically, it's a direction PLUS a distance that's invariant under 
rotation or translation of the coordinate system in which it's embedded. 
:-) Otherwise, it's just a tuple.

-- 
   Darren New / San Diego, CA, USA (PST)
     Scruffitarianism - Where T-shirt, jeans,
     and a three-day beard are "Sunday Best."


Post a reply to this message

From: Thomas de Groot
Subject: Re: Use Slope pattern for Planting distribution?
Date: 13 Dec 2006 02:54:05
Message: <457fb19d$1@news.povray.org>
"Kirk Andrews" <kir### [at] hotmailcom> schreef in bericht 
news:web.457eb359aa33b1599033e1160@news.povray.org...
> I'm trying to use the trace command to plant grass on my Isosurface
> landscape, but I don't want it to "grow" on steep grades.  Is it possible
> to use the slope pattern to control my distribution, or is there another
> way to do this?
>

All the answers given so far are excellent, however, I think you need an 
example scene now to understand it fully (I did).
I shall post one today in p.b.s-f under the same header.

Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: Use Slope pattern for Planting distribution?
Date: 13 Dec 2006 03:05:32
Message: <457fb44c$1@news.povray.org>
In fact, It is such a small piece of code, that I can post it here below.

Thomas

//=======================================================================================
// -------- Placing the trees -------------
#debug "Placing trees...\n"

#declare Spacing = 1;
#declare Cnt = 0;


#declare PosX = -15;

#while (PosX < 15)

  #declare PosZ = -25;

  #while (PosZ < 15)

    // trace function
    #declare Norm = <0, 0, 0>;
    #declare Start = <PosX+(rand(Seed)-0.5)*Spacing, 
UpperBound+Isoscale.y+1, PosZ+(rand(Seed2)-0.5)*Spacing>;
    #declare Pos = trace (
                          Landscape,       // object to test
                          Start,           // starting point
                          -y,              // direction
                          Norm );          // normal


    #if (Norm.x != 0 | Norm.y != 0 | Norm.z != 0)   // if intersection is 
found, normal differs from 0
      #if ((vdot(Norm, y)>0.5) & (Pos.y < 5.5))     // criteria for placing 
trees: not too steep and not too high
        object {
          //Tree (0.5+rand(Seed)*0.02)
          TREE
          scale RRand(1.0, 2.5, Seed)
          rotate RRand(0, 360, Seed2)*y
          translate Pos
        }
        #declare Cnt = Cnt+1;
      #end
    #end

    #declare PosZ = PosZ+Spacing;

  #end

  #declare PosX = PosX+Spacing;
#end
#debug concat("Placed ", str(Cnt,0,0), " Trees\n")

#end
//=======================================================================================


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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