POV-Ray : Newsgroups : povray.general : random distribution in an object Server Time
4 Nov 2024 23:16:13 EST (-0500)
  random distribution in an object (Message 1 to 7 of 7)  
From: Rohan Bernett
Subject: random distribution in an object
Date: 11 Sep 2003 23:05:01
Message: <web.3f613654e0899c95dd7b64e70@news.povray.org>
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

From: JC (Exether)
Subject: Re: random distribution in an object
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

From: Christoph Hormann
Subject: Re: random distribution in an object
Date: 12 Sep 2003 03:27:27
Message: <07c831-ia7.ln1@triton.schunter.etc.tu-bs.de>
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?

Have a look at the inside() function.  It works for all objects ith well 
defined inside and outside (like isosurfaces)

Christoph

-- 
POV-Ray tutorials, include files, Sim-POV,
HCR-Edit and more: http://www.tu-bs.de/~y0013390/
Last updated 17 Jun. 2003 _____./\/^>_*_<^\/\.______


Post a reply to this message

From: Warp
Subject: Re: random distribution in an object
Date: 12 Sep 2003 05:19:54
Message: <3f618fba@news.povray.org>
Christoph Hormann <chr### [at] gmxde> wrote:
> Have a look at the inside() function.  It works for all objects ith well 
> defined inside and outside (like isosurfaces)

  You can place *points* inside an object with this method. However, how
can you place objects with dimensions randomly inside another object (and
be sure that no part of the first object comes out of the second)?

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: JC (Exether)
Subject: Re: random distribution in an object
Date: 12 Sep 2003 08:39:12
Message: <3f61be70@news.povray.org>
You can check that the bounding box edges of the object you insert are 
also inside the object in which you insert, that still isn't perfect but 
you can generalise that to check that condition on points of a grid 
within the object you want to insert, that way you would asymptotically 
get close to the solution.

But sometimes you insert such small objects that you don't really need 
to check that they don't come out.

JC

Warp wrote:
> Christoph Hormann <chr### [at] gmxde> wrote:
> 
>>Have a look at the inside() function.  It works for all objects ith well 
>>defined inside and outside (like isosurfaces)
> 
> 
>   You can place *points* inside an object with this method. However, how
> can you place objects with dimensions randomly inside another object (and
> be sure that no part of the first object comes out of the second)?
>


Post a reply to this message

From: Tom Melly
Subject: Re: random distribution in an object
Date: 12 Sep 2003 08:49:39
Message: <3f61c0e3@news.povray.org>
"JC (Exether)" <no### [at] spamfr> wrote in message news:3f61be70@news.povray.org...
>
> But sometimes you insert such small objects that you don't really need
> to check that they don't come out.

If I see you dating my sister, you're a dead man.


Post a reply to this message

From: JC (Exether)
Subject: Re: random distribution in an object
Date: 15 Sep 2003 03:18:53
Message: <3f6567dd$1@news.povray.org>
:-)))

Ooopss ...

Tom Melly wrote:
> "JC (Exether)" <no### [at] spamfr> wrote in message news:3f61be70@news.povray.org...
> 
>>But sometimes you insert such small objects that you don't really need
>>to check that they don't come out.
> 
> 
> If I see you dating my sister, you're a dead man.
> 
>


Post a reply to this message

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