POV-Ray : Newsgroups : povray.advanced-users : Trees on landscape--uneven distribution Server Time
25 Nov 2024 12:57:03 EST (-0500)
  Trees on landscape--uneven distribution (Message 1 to 4 of 4)  
From: John Haiducek
Subject: Trees on landscape--uneven distribution
Date: 24 Nov 2002 16:40:09
Message: <web.3de145fc81186a0c890025210@news.povray.org>
I'm trying to place trees on a landscape using the trace() function so
they're only placed in view of the camera.  The script I have places most of
the trees very close to the camera.  Does anyone know how to do this so I
get an even distribution of trees, all within the camera's view?

Here's my code:
#declare i=0;
#declare r1=seed(256);
#declare r2=seed(100);
#declare N=<0,0,0>;
while(i<10000)
  #declare
dir=vaxis_rotate(camera_look_at-camera_location,vcross(camera_look_at-camera
_location,camera_up),(rand(r1)-.5)*camera_angle);
  #declare dir=vaxis_rotate(dir,camera_up,(rand(r1)-.5)*camera_angle*4/3);
  #declare X=trace(terrain,camera_location,dir,N);
  #if(vlength(N)>0)
      object{
        cone{0,1.5,7*y,0 pigment{rgb <0,1,0>} scale .5+.5*rand(r1) translate
X}
      }
  #end
  #declare N=<0,0,0>;
  #declare i=i+1;
#end


Post a reply to this message

From: Christopher James Huff
Subject: Re: Trees on landscape--uneven distribution
Date: 24 Nov 2002 18:54:27
Message: <chrishuff-2A7AFE.18515624112002@netplex.aussie.org>
In article <web.3de145fc81186a0c890025210@news.povray.org>,
 "John Haiducek" <c06### [at] usafaafmil> wrote:

> I'm trying to place trees on a landscape using the trace() function so
> they're only placed in view of the camera.  The script I have places most of
> the trees very close to the camera.  Does anyone know how to do this so I
> get an even distribution of trees, all within the camera's view?

I guess you are doing this by placing trees where the base is visible 
from the camera, this will never work correctly...many trees are visible 
without their bases being visible. Try placing the trees evenly on the 
landscape, only placing a tree when the top of the tree is visible. 
(Where there is no intersection on a ray between the top of the tree and 
the camera, maybe also taking camera angle into account.) It would be 
easier to start with a even random distribution and "weed out" the ones 
that aren't visible.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Mark Weyer
Subject: Re: Trees on landscape--uneven distribution
Date: 25 Nov 2002 06:44:54
Message: <3DE20F78.8D7695A0@frege.mathematik.uni-freiburg.de>
> I'm trying to place trees on a landscape using the trace() function so
> they're only placed in view of the camera.  The script I have places most of
> the trees very close to the camera.  Does anyone know how to do this so I
> get an even distribution of trees, all within the camera's view?

First order approximation to what you want:

- Choose a basic probability p.
- Choose dx and dy adequately small.
- Trace the ray, resulting in a point P0=<x,y,z> on the landscape.
- Calculate the points P1=<x+dx,y,z1> and P2=<x,y+dy,z2> of the
landscape
  (i.e. calculate z1 and z2)
- Calculate the area A _OF THE IMAGE_ that the triangle P0-P1-P2 would
use.
- Put a tree with probability p/A. Beware of division by zero.

Enhancements:
- Combine with Christopher's suggestion
- Scatter the tree base positions, so they are not only where the rays
hit.

Regards,

  Mark


Post a reply to this message

From: Mark Weyer
Subject: Re: Trees on landscape--uneven distribution
Date: 25 Nov 2002 11:30:53
Message: <3DE2527E.7E59A3A8@frege.mathematik.uni-freiburg.de>
> - Choose a basic probability p.
> [...]
> - Calculate the area A _OF THE IMAGE_ that the triangle P0-P1-P2 would
> [...]
> - Put a tree with probability p/A. Beware of division by zero.

I was previously in a hurry. Here is a more refined version:
Let A0 be the area of the image between three ,,adjacent'' rays.
Let d be the desired density of trees, i.e. in average there
should be one tree in an area of 1/d.

Then put a tree with probability d*dx*dy*A0/A, i.e. choose p=d*dx*dy*A0.

Regards,

  Mark


Post a reply to this message

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