Showing posts with label generation. Show all posts
Showing posts with label generation. Show all posts

Friday, August 18, 2017

Points inside a ellipsoid

Generates a list of random points that lie inside a ellipsoid

function random_points_inside_ellipsoid(rx,ry,rz,n)=
[for(i=[1:n])ellipsoid_point(rx,ry,rz)];

function ellipsoid_point(rx,ry,rz)=
let (
r=[rx,ry,rz],
p=[
rands(-rx,rx,1)[0],
rands(-ry,ry,1)[0],
rands(-rz,rz,1)[0] 
] ,
d= ((
sq2(p.x)/sq2(r.x)+
sq2(p.y)/sq2(r.y)+
sq2(p.z)/sq2(r.z)) - 1) * min(r.x,r.y,r.z)  ) 
 (d)>0?ellipsoid_point(rx,ry,rz):p;
function sq2(v)=pow(v,2);

p=random_points_inside_ellipsoid(50,50,100,1000);
for(t=p)translate(t)sphere(4);
echo(p);
 

Tuesday, August 8, 2017

Points Inside A Cylinder


Generates a list of random points that lie inside a cylinder

function random_points_inside_cylinder(r,h,n)=
[for(i=[1:n])cylinder_point(r,h)];

function cylinder_point(r,h)=
let (p=[
rands(-r,r,1)[0],
rands(-r,r,1)[0],
rands(0,h,1)[0] ],
d=(pow(p.x,2) + pow(p.y,2) )) 
d > pow(r,2)?cylinder_point(r,h):p;


p=random_points_inside_cylinder(50,100,1000);
for(t=p)translate(t)sphere(4);
echo(p);
 

Sunday, August 6, 2017

Points inside a tube


Generates a list of random points that lie inside a tube

function random_points_inside_tube(r,r2,h,n)=
          [for(i=[1:n])tube_point(r,r2,h)];

function tube_point(r,r2,h)=
let (p=[
rands(-r,r,1)[0],
rands(-r,r,1)[0],
rands(0,h,1)[0] ],
d=(pow(p.x,2) + pow(p.y,2) ))

 d > pow(r,2)||d < pow(r2,2)?tube_point(r,r2,h):p;


p=random_points_inside_tube(50,30,100,1000);
for(t=p)translate(t) sphere(4);
echo(p);
 

Friday, August 4, 2017

Points inside a cone

Generates a list of random points that lie inside a cone

function random_points_inside_cone(r,h,n)=
   [for(i=[1:n])cone_point(r,h)];

function cone_point(r,h)=
let (p=[
rands(-r,r,1)[0],
rands(-r,r,1)[0],
rands(0,h,1)[0] ],
d=sqrt(pow(p.x,2) + pow(p.y,2) ) 
)  
d > r-r*(p.z/h)?cone_point(r,h):p;


p=random_points_inside_cone(50,150,2000);
for(t=p)translate(t)rotate(rands(0,360,3))cube(5,center=true);
echo(p);
 

Tuesday, June 20, 2017

Points inside a cube

Generates a list of random points that lie inside a cuboid.

function random_points_inside_cuboid(p1,p2,n)=
    [for(i=[1:n])cuboid_point(p1,p2)];

function cuboid_point(p1,p2)= 
  [rands(-p1.x,p2.x,1)[0],
   rands(-p1.y,p2.y,1)[0],
   rands(-p1.z,p2.z,1)[0]] ;

 


p1=[0,0,0];
p2=[100,100,100];
p=random_points_inside_cuboid(p1,p2,1000);
for(t=p)translate(t)sphere(4);
echo(p);
 

Friday, June 16, 2017

Points inside a sphere

Generates a list of random points that lie inside a sphere

function random_points_inside_sphere(r,n)=
[for(i=[1:n])sphere_point(r)];

function sphere_point(r)=
let (p=rands(-r,r,3)) 
(pow(p.x,2) + pow(p.y,2) + pow(p.z,2) > pow(r,2))?sphere_point(r):p;


p=random_points_inside_sphere(50,1000);
for(t=p)translate(t)sphere(4);
echo(p);