![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Hi all,
I have created a macro to create an object. I now want to randomly place the
object in my scene (within specified boundaries!!)
How do I get POVRay to generate random numbers?
Thanks,
Reuben
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
The simplest way to do this is:
#declare lower_bound = something;
#declare upper_bound = somethingelse;
#declare MySeed = seed(2531); // or some other number, big and prime is nice
object { whatever
translate lower_bound + rand(MySeed)*(upper_bound - lower_bound) }
// end
something and something else can be vectors, but they will distribute within a
straight line, so you will have to do this in triplicate for three different
vectors to fill space.
Reuben Pearse wrote:
> Hi all,
>
> I have created a macro to create an object. I now want to randomly place the
> object in my scene (within specified boundaries!!)
> How do I get POVRay to generate random numbers?
>
> Thanks,
>
> Reuben
--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritone com
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/
"He who hebetates is last."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Reuben Pearse wrote:
>
> I have created a macro to create an object. I now want to randomly place the
> object in my scene (within specified boundaries!!)
> How do I get POVRay to generate random numbers?
>
First you have to declare a random number seed, like this:
#declare RandSeed = seed(N); //N is a random integer of your choice
The you can call the rand() function, with the name of the seed identifier as
the parameter, for examle like this:
#declare RandomValue=rand(RandSeed);
Each time you call rand(RandSeed) a different (pseudo)random value is returned
from the stream initialized by RandSeed.
For creating random numbers of a given mean value and maximum deviation, you can
try these macros (the first returns a float, the second depends on the first and
returns a 3D vector):
//Create random number of given mean and maximum deviation
//M - mean value
//D - maximum deviation
//Seed - (declared) random number seed identifier
#macro rand_ext(M,D,Seed)
(M+(rand(Seed)-.5)*2*D)
#end
//Give a random vector of given mean and max deviation
//M - mean (vector or float)
//D - max deviation (vector or float)
//Seed - (declared) random number seed identifier
#macro v_rand_ext(M,D,Seed)
#local MV=M+<0,0,0>;
#local DV=D+<0,0,0>;
(<rand_ext(MV.x,DV.x,Seed),
rand_ext(MV.y,DV.y,Seed),
rand_ext(MV.z,DV.z,Seed)>)
#end
--
Margus Ramst
Personal e-mail: mar### [at] peak edu ee
TAG (Team Assistance Group) e-mail: mar### [at] tag povray org
Home page http://www.hot.ee/margusrt
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
In article <3A9A89B3.F7059895@spiritone.com>, Josh English
<eng### [at] spiritone com> wrote:
> something and something else can be vectors, but they will distribute
> within a straight line, so you will have to do this in triplicate for
> three different vectors to fill space.
Triplicate for three different vectors? Not quite, you just need three
calls to rand()...try these macros:
// "signed rand", ranges from -1 to 1
#macro SRand(RS) (rand(RS)*2 - 1) #end
// "ranged rand"
#macro RRand(Mn, Mx, RS) (Mn + rand(RS)*(Mx-Mn)) #end
// random point in cube from Mn to Mx
#macro RandPt(Mn, Mx, RS)
(Mn + < rand(RS), rand(RS), rand(RS)>*(Mx-Mn))
#end
--
Christopher James Huff
Personal: chr### [at] mac com, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tag povray org, http://tag.povray.org/
<><
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Chris Huff wrote:
> In article <3A9A89B3.F7059895@spiritone.com>, Josh English
> <eng### [at] spiritone com> wrote:
>
> > something and something else can be vectors, but they will distribute
> > within a straight line, so you will have to do this in triplicate for
> > three different vectors to fill space.
>
> Triplicate for three different vectors? Not quite, you just need three
> calls to rand()...try these macros:
>
> // "signed rand", ranges from -1 to 1
> #macro SRand(RS) (rand(RS)*2 - 1) #end
>
> // "ranged rand"
> #macro RRand(Mn, Mx, RS) (Mn + rand(RS)*(Mx-Mn)) #end
>
> // random point in cube from Mn to Mx
> #macro RandPt(Mn, Mx, RS)
> (Mn + < rand(RS), rand(RS), rand(RS)>*(Mx-Mn))
> #end
I feel so stupid for missing that. No wonder I gave up programming
--
Josh English -- Lexiphanic Lethomaniac
eng### [at] spiritone com
The POV-Ray Cyclopedia http://www.spiritone.com/~english/cyclopedia/
"He who hebetates is last."
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |