|
|
"Bald Eagle" <cre### [at] netscapenet> wrote:
I've done the VRand_ON_Box (RandSeed) awhile ago for my MeshTree project
along with VRand_ON_Cone,VRand_IN_Cone, VRand_ON_Cylinder, VRand_IN_Cylinder
I used them to place the end points of a binary tree.
When I looked back on them I found that the Cone marcos use a cone with a base
pov unit from <0,0,0,> the end point 1 unit in opposite direction 1 with the
base radius 1 and the other radius 0 and you had a choice of 3 directions to
place it
(x,y,z). The On_Cone also had the OPEN option.
The cylinder macro has the same basic lay out.
They work great for making trees but I don't know if they have an even
distribution.
Here they are copied from the modified rand.inc I use.
//a random point ON a square box {-1, 1}
#macro VRand_On_Box(R)// LR added
#local V=<0,0,0>;
#local a=int(rand(R)*6);
#switch (a)
#case(0)#local V=<-1,rand(R)*2-1,rand(R)*2-1>; #break
#case(1)#local V=<1,rand(R)*2-1,rand(R)*2-1>; #break
#case(2)#local V=<rand(R)*2-1,-1,rand(R)*2-1>; #break
#case(3)#local V=<rand(R)*2-1,1,rand(R)*2-1>; #break
#case(4)#local V=<rand(R)*2-1,rand(R)*2-1,-1>; #break
#case(5)#local V=<rand(R)*2-1,rand(R)*2-1,1>; #break
#end
(V)
#end
//a random point ON a Cylinder from -1 to 1 in the D direction
// radius=1
// if O open cylinder
// D=1 +y direction
// D=2 +x direction
// D=3 +z direction
#macro VRand_On_Cyl(D,O,R)// LR added
#local Theta = 2*pi*rand(R);
#local V=<0,0,0>;
#local H=rand(R)*2-1;
#local S=1; // radius
#if(O) #local Hv=1;
#else #local Hv=.95;
#end
#if (H>Hv) #local S=rand(R);#local H=1; #end
#if (H<-Hv) #local S=rand(R);#local H=0; #end
#if (D=1)#local V= <H,cos(Theta)*S,sin(Theta)*S>; #end
#if (D=2)#local V= <cos(Theta)*S,H,sin(Theta)*S>; #end
#if (D=3)#local V= <cos(Theta)*S,sin(Theta)*S,H>; #end
(V)
#end
//a random point IN a Cylinder from -1 to 1 in the D direction
// D=1 +y direction
// D=2 +x direction
// D=3 +z direction
#macro VRand_In_Cyl(D,R)// LR added
#local Theta = 2*pi*rand(R);
#local V=<0,0,0>;
#local H=rand(R)*2-1;
#local S=rand(R);
#if (D=1)#local V= <H,cos(Theta)*S,sin(Theta)*S>; #end
#if (D=2)#local V= <cos(Theta)*S,H,sin(Theta)*S>; #end
#if (D=3)#local V= <cos(Theta)*S,sin(Theta)*S,H>; #end
(V)
#end
//a random point ON a Cone from -1,1 to 1,0 in the D direction
// more values in the lower part
// if O open Cone
// D=1 +x direction
// D=2 +y direction
// D=3 +z direction
#macro VRand_On_Cone(D,O,RS)// LR added
#local Rt=rand(RS);
#local Rv=Rt*Rt;
#local Theta = 2*pi*rand(RS);
#local V=<0,0,0>;
#local H=Rv*2-1;
#local S=1-(H+1)/2;
#if(H<-.95 & O=0) #local S=rand(RS); #local H=-1;#end
#if (D=1)#local V= <H,cos(Theta)*S,sin(Theta)*S>; #end
#if (D=2)#local V= <cos(Theta)*S,H,sin(Theta)*S>; #end
#if (D=3)#local V= <cos(Theta)*S,sin(Theta)*S,H>; #end
(V)
#end
//a random point IN a Cone from -1,1 to 1,0 in the D direction
// more values in the lower part
// D=1 +y direction
// D=2 +x direction
// D=3 +z direction
#macro VRand_In_Cone(D,RS)// LR added
#local Rt=rand(RS);
#local Rv=Rt*Rt;
#local Theta = 2*pi*rand(RS);
#local V=<0,0,0>;
#local H=Rv*2-1;
#local S=1-(H+1)/2;
#local S=S*rand(RS);
#if (D=1)#local V= <H,cos(Theta)*S,sin(Theta)*S>; #end
#if (D=2)#local V= <cos(Theta)*S,H,sin(Theta)*S>; #end
#if (D=3)#local V= <cos(Theta)*S,sin(Theta)*S,H>; #end
(V)
#end
Post a reply to this message
|
|