POV-Ray : Newsgroups : povray.general : random distribution in an object : Re: random distribution in an object Server Time
4 Nov 2024 21:26:31 EST (-0500)
  Re: random distribution in an object  
From: JC (Exether)
Date: 12 Sep 2003 03:19:58
Message: <3f61739e@news.povray.org>
The inside primitive might come handy for your purpose.
Here is a macro I wrote for the french "boxed" challenge ( 
http://povgaleries.tuxfamily.org/defis/PageDefi003.php ), it positions N 
subobj inside the obj along a grid of NxNxN, it also moves a bit the 
positions randomly, so it is not really a random repartition, but I 
think that little changes would make it random.

I hope that's what you're looking for,

JC


#macro sub_objectise (obj, subobj, N, TheSeed)
   #local Pmin=min_extent (obj);
   #local Pmax=max_extent (obj);
   #local delta_obj=(Pmax-Pmin)/(2*N);
   #local i=0;
   #while (i<N)
     #local j=0;
     #while (j<N)
       #local k=0;
       #while (k<N)
	// On prend une position dans la grille et on la decale un peu
         // pour eviter que tout soit aligne.
	#local Pos=<Pmin.x+(Pmax.x-Pmin.x)*i/N,
	            Pmin.y+(Pmax.y-Pmin.y)*j/N,
	            Pmin.z+(Pmax.z-Pmin.z)*k/N>+
	           <rand(MySeed)*delta_obj.x,
                     rand(MySeed)*delta_obj.y,
                     rand(MySeed)*delta_obj.z>;
	#if (inside (obj, Pos) >= 1.0)
	  #local a1=360*rand(TheSeed);
	  #local a2=360*rand(TheSeed);
	  #local a3=360*rand(TheSeed);
	  object { subobj rotate <a1,a2,a3> translate Pos }
	#end
	#local k = k + 1;
       #end
       #local j = j + 1;
     #end
     #local i = i + 1;
   #end
#end


Rohan Bernett wrote:
> I'd like to randomly position some objects inside an isosurface, but I have
> no idea as to how to do it. Can anyone help me? Also, would it be possible
> to extend this to an arbitary object?
> 
> Rohan _e_ii
>


Post a reply to this message

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