Monday, December 18, 2017

Unique With Order Preserved

Remove duplicates from a list with order preserved.


function unique(m)=
     [for(i=[0:len(m)-1])if(search([m[i]],m,1)==[i])m[i]];
 

Friday, December 15, 2017

Clamp For List

Clamp every number in a list structure between two boundary numbers.

echo(clamplist([10,-.20,03,40,21,1,0,0.6,-2]));

function clamplist(v,b=0,c=1) = 
len(v) == undef ? min(max(v,min(b,c)),max(b,c)): 
len(v) == 0 ? [] : 
[for (i = v) clamplist(i,b,c)];

 

Tuesday, December 12, 2017

Select random item from a list

Select random item from a curated collection.

My_selection=sel_rnd( [1, 3, 0.5, 100, sin(2)]  );

function sel_rnd(v)=v[floor(rnd(len(v)))];

 

Friday, December 1, 2017

Fit a 4 point bezier curve for desired length

module to draw a simple 4 point Bez curve. 
function for piece-wise length  estimation. 

And a recursive function to fit control points for the length of your pleasure. 

function AdjustBezier(v,l, precision = 0.00001)=
l<norm(v[0]-v[3])?
let(e=echo("Cant be that short, sorry"))[v[0],v[0] ,v[3] ,v[3]]:
let(
current_lenght=len3bz(v),
error=l/current_lenght,
e=echo(l,current_lenght,error),
new_v=[v[0],v[0]+(v[1]-v[0])*error,v[3]+(v[2]-v[3])*error,v[3]]
)
abs(1-error)>precision?AdjustBezier(new_v,l):v;



function len3bz(v, precision = 0.001, t = 0, acc = 0) =
 t > 1 ? acc : 
len3bz(v, precision, t + precision, acc 
+ norm(bez2(t, v) - bez2(t + precision, v)));

function bez2(t, v) = (len(v) > 2) ? bez2(t, [
  for (i = [0: len(v) - 2]) v[i]* (t)  + v[i + 1] * (1 - t)
]): v[0]* (t)  + v[1]* (1 - t) ;

module ShowControl(v) { // translate(t(v[0])) sphere(v[0][3]);
 
    for (i = [1: len(v) - 1]) {
      // vg  translate(t(v[i])) sphere(v[i][3]);
      hull() {
        translate(t(v[i])) sphere(0.5);
        translate(t(v[i - 1])) sphere(0.5);
      }
    }
}

module ShowBezier(v,steps=50) 
{ // translate(t(v[0])) sphere(v[0][3]);
 step=1/steps;
    for (i = [-step:step:  1+step]) {
      // vg  translate(t(v[i])) sphere(v[i][3]);
      hull() {
        translate(t(bez2(clamp(i), v) ))sphere(1);
        translate(t(bez2(clamp(i+step), v))) sphere(1);
      }
    }
}


function t(v) = [v.x, v.y, v.z];
function clamp(a, b = 0, c = 1) = min(max(a, b), c);

MyBezier=[[0,0,0],[0,0,10],[50,0,50],[50,10,50]];
Newlengh=175;

ShowControl(MyBezier) ; 
ShowBezier(MyBezier) ;
echo(len3bz(MyBezier));

MyNewBezier=AdjustBezier(MyBezier,Newlengh) ;

color("red"){
ShowControl(MyNewBezier) ; 
ShowBezier(MyNewBezier) ;
echo(len3bz(MyNewBezier));}

Wednesday, October 11, 2017

0 - 1 Remapping Functions: Compressor / Expander / Biramp

/* remapping functions */

v1=rnd();v2=rnd(); 

for(i=[-0:1/160:1])translate([i,0])square([1/160,  ((  comp(i,v1,v2)))]);
    function comp(i,c=0.5,s=0.75)=i<c? ramp(i,0,c,0,s) :ramp(i,c,1,s,1) ;
    function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
        let(b1=min(bi1,bi2),b2=max(bi1,bi2))
        v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;
     function lerp(start, end, bias) = (end * bias + start * (1 - bias));

function rnd(a = 1, b = 0, s = []) = 
  s == [] ? 
   (rands(min(a, b), max(   a, b), 1)[0]) 
  : 
   (rands(min(a, b), max(a, b), 1, s)[0])
  ; 



Monday, October 9, 2017

0 - 1 Remapping Functions: Map / BiSignMap / InfMap

/* remapping functions */


for(i=[-1:1/160:1])translate([bisignmap(i),0])square([1/160,  map(infmap(i*12) )   ]);

// Map takes a number in some range 
// and remaps it into the desired range
function  map(  value,istart=-1, istop=1, ostart=0, ostop=1) =
ostart + (ostop - ostart) * ((value - istart) / (istop - istart));

// BiSignMap takes a number in the range -1 - 1
// and remaps it into the range 0 - 1.
function bisignmap(i)=(i+1)/2;

// InfMap takes a number in the range -inf - inf
// and remaps it into the range -1 - 1 . 
function infmap(i)=max(0,1-(1/(abs(i)+1)))*sign(i);

Saturday, October 7, 2017

0 - 1 Remapping Functions: Smooth Step 2

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   smooth2(i) )) ]);
     function smooth2(x,k=5,n=4) =1- (exp( -k*pow(x,n) ));
 

Compared to smooth step

Thursday, October 5, 2017

0 - 1 Remapping Functions: Power Smooth / Inverse Power Smooth

/* remapping functions */



for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   powersmooth(i) )) ]);
     function powersmooth(x) =       ((x+ x-ipowersmooth(x))-0.5)*0.9+0.5 ;

for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   ipowersmooth(i) )) ]);
    function ipowersmooth(x) =  clamp(pow(x-0.5,3)*4+0.5);
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
 


Tuesday, October 3, 2017

0 - 1 Remapping Functions: Powers 10 to -10

/* remapping functions */



for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   power(i,10) )) ]);
     function power(x,n) = n<0?pow(x,1/abs(min(-1,n-1) )):pow(x,max(1,n+1))   ;


for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (   power(i,-10) )) ]);
     function power(x,n) = n<0?pow(x,1/abs(min(-1,n-1) )):pow(x,max(1,n+1))   ;
 


Sunday, October 1, 2017

0 - 1 Remapping Functions: Multiple Smooth Steps

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,   (smooths(  smooth(i),3 )) ]);
    function smooths(v,steps) =smooth( smooth(mods(v,steps) ))/steps+mstep(v,steps);
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
    function mods(v,steps=3) = ( (v*steps)%1);
 


Friday, September 29, 2017

0 - 1 Remapping Functions: Inverse Cosine-Wave

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,    (icosw(  (i))) ]);
     function icosw(i)=-cos(i*360)/2+0.5+i;
 

 

Monday, September 25, 2017

0 - 1 Remapping Functions: Cosine-Wave

/* remapping functions */


for(i=[-0:1/160:1])translate([i ,  min(0,cosw(i))])
                 square([1/160,   abs(cosw(  (i))) ]);
    function cosw(i)=cos(i*360)/2 -0.5+i;
 

 

Saturday, September 23, 2017

0 - 1 Remapping Functions: Inverse Sine-Wave

/* remapping functions */


for(i=[-0:1/160:1])translate([i,  min(0,isinw(i))])
                square([1/160,   abs(isinw(  (i))) ]);
    function isinw(i)=gauss(i)-sin(i*360)/2;
 
    function gauss(x) =       x + (x - smooth(x));
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);

 

Thursday, September 21, 2017

0 - 1 Remapping Functions: Sine-Wave

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,    (sinw(  (i))) ]);
    function sinw(i)=sin(i*360)/2+smooth(i);
    function gauss(x) =       x + (x - smooth(x));
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);

 

Tuesday, September 19, 2017

0 - 1 Remapping Functions: Multiple Arcs 2

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160,   (arcs2(  (i),3)) ]);
    function arc1 (x,n=0) = let(a= n>0? arc1(x,(n-1)):x) clamp(sqrt(1-(1-a)*(1-a)));
    function arc2 (x,n=0) =let(a= n>0? arc2(x,(n-1)):x) clamp( 1-sqrt(1-(a)*(a)));
    function arcs1(v,steps=3) = arc1(mods(v,steps),1)/steps+mstep(v,steps);
    function arcs2(v,steps=3) = arc2(mods(v,steps),1)/steps+mstep(v,steps);
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
    function mods(v,steps=3) = ( (v*steps)%1);
 


0 - 1 Remapping Functions: Multiple Arcs 1

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160,   (arcs2(  (i),3)) ]);
    function arc1 (x,n=0) = let(a= n>0? arc1(x,(n-1)):x) clamp(sqrt(1-(1-a)*(1-a)));
    function arc2 (x,n=0) =let(a= n>0? arc2(x,(n-1)):x) clamp( 1-sqrt(1-(a)*(a)));
    function arcs1(v,steps=3) = arc1(mods(v,steps),1)/steps+mstep(v,steps);
    function arcs2(v,steps=3) = arc2(mods(v,steps),1)/steps+mstep(v,steps);
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
    function mods(v,steps=3) = ( (v*steps)%1);
 

Sunday, September 17, 2017

0 - 1 Remapping Functions: Gauss

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,   (gauss(  (i))) ]);
    function gauss(x) =       x + (x - smooth(x));
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c)
 

Friday, September 15, 2017

0 - 1 Remapping Functions: Step Ramp

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160,   ( (  stepramp(i,bi1=1/5,bi2=4/5,start=1/3, end=2/3) )) ]);

function stepramp(v,bi1=1/5,bi2=4/5,start=1/3, end=2/3) = 
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?ramp(v,0,b1,0,start):v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :ramp(v,b2,1,end,1);

function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
let(b1=min(bi1,bi2),b2=max(bi1,bi2))
v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;


function lerp(start, end, bias) = (end * bias + start * (1 - bias));

 

Wednesday, September 13, 2017

0 - 1 Remapping Functions: Ramp

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])
        square([1/160, (ramp( (i),1/3,2/3,0.1)) ]);
function ramp(v,bi1=1/3,bi2=2/3,start=1/3, end=2/3) = 
        let(b1=min(bi1,bi2),b2=max(bi1,bi2))
        v<=b1?start:v<=b2?lerp(start,end,(v-b1)/(b2-b1))    :end;
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
 

Monday, September 11, 2017

0 - 1 Remapping Functions: Arc 2

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160,  (arc2(  (i)))]);
function arc2 (x,n=0) =
     let(a= n>0? arc2(x,(n-1)):x) clamp( 1-sqrt(1-(a)*(a)));    
function clamp(a, b = 0, c = 1) = min(max(a, b), c);
 

Saturday, September 9, 2017

0 - 1 Remapping Functions: Arc 1

/* remapping functions */


 for(i=[-0:1/160:1])translate([i,0])square([1/160,  (arc1(  (i)))]);
 function arc1 (x,n=0) = let(a= n>0? arc1(x,(n-1)):x) clamp(sqrt(1-(1-a)*(1-a)));
 function clamp(a, b = 0, c = 1) = min(max(a, b), c);
 

Thursday, September 7, 2017

0 - 1 Remapping Functions: Smooth Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (smooth( (i),2/3,0.1))]);
    function smooth (a) =let (b = clamp(a))(b * b * (3 - 2 * b));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c)
 

Tuesday, September 5, 2017

0 - 1 Remapping Functions: Modulus

/* remapping functions */

for(i=[-0:1/160:1])translate([i,0])square([1/160, (mods(  (i),5))]);
    function mods(v,steps=3) = ( (v*steps)%1);
 

Sunday, September 3, 2017

0 - 1 Remapping Functions: Multi Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (mstep( i,5))]);
    function mstep(v,steps=3) = (floor(v*steps)/steps );
 

Friday, September 1, 2017

0 - 1 Remapping Functions: Step

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160, (step( (i),2/3,0.1))]);
    function step(v,bias,start=0, end=1) = v>=bias?end:start;
 

Wednesday, August 30, 2017

Wrap number

Wraps numbers inside boundaries
 Usage:



function wrap(x,x_max=1,x_min=0) = 
(((x-x_min)%(x_max-x_min))+(x_max-x_min))%(x_max-x_min)+x_min; 
// wraps numbers inside boundaries
 

Monday, August 28, 2017

Radius A Regular Polygon By Side And N



function Radius_A_Regular_Polygon_By_Side_And_N(A,N)= A/(2*sin/(180/N));

 

Saturday, August 26, 2017

Area Of A Isosceles Prism By Base Heights



function Area_Of_A_Isosceles_Prism_By_Base_Heights(A,h,H)=
    2*((1/2)*A*h)+ A*sqrt((a/2)*(a/2)+h*h)*H;
 

Thursday, August 24, 2017

Tennis ball curve function.

Tennis ball curve function. Returns a single point at (i) far along a curve in the shape of  the seam on a tennis ball.

function Tennis_ball_Curve(i)=let( 
b=360*i-sin(360*i*4)*25 ,
a=sin(360*i*2)*65)
[cos(a)*sin(b),cos(a)*cos(b),sin(a)] ;

for(i=[0:1/180:1]){
translate(Tennis_ball_Curve(i))sphere(0.02,$fn=30);
} 

Tuesday, August 22, 2017

Log spiral function

Log spiral function. Returns a single point at (a) far along a spiral curve defined by radius  number of turns and exponent for falloff. Both turns and exponent can be negative to positive numbers.


function L_Spiral (a,radius = 50,heigth,turns =  4,xpnt=0.685,start_angle=45)
= let( fx = xpnt<0?
pow(max(0,1-a),1/abs(min(-1,xpnt-1) )): pow(max(0,1-a),max(1,xpnt+1))   ) 
[(radius * fx ) * cos(start_angle+ a* turns*360*sign(turns)),
 (radius * fx ) * sin(start_angle+ a* turns*360*sign(turns)),a*heigth];

for(j=[0:1/60:1]){hull(){
 translate(L_Spiral (j, 50,-150,  4, 1.685, 0 ))sphere();
 translate(L_Spiral (j+1/60, 50,-150, 4, 1.685, 0 ))sphere();
}}
 
 

Lets try The Anet A8 from GearBest

After several bad experiences of low price kits which have taken too many shortcuts, I was very skeptical to try out the Anet A8. I expected a challenge, but the kit arrived complete and in order, slightly unpolished, but a lot better than expected to the price point.


Of course, it takes many hours to assemble an Anet A8, if you want to do it carefully. No steps were particularly difficult, but to make sure to review the inherent quality, not my own sloppiness, I took the time to do everything carefully without haste. The less you pay the more you are expected to do yourself. Sometimes instructions were quite confusing but far from impossible. The whole thing is a good fun assembly experience that most people can manage if they follow the video clips found online.


Anet A8 is a typical Prusa clone with few excesses. Most subsystems are variations of well-proven constructions, albeit in their most affordable form. Reliable, but these clones contributes very little innovation to the 3d printer community. The contribution, instead, is to be able to put affordable machines in the hands of tens of thousands of users who never had the chance before. Much like Clive Sinclair's Z80 computers in the 80's. And just like them, Anet A8 is so slimmed down on parts quality that it just barely works without further upgrades and frequent maintenance. These deliberately cut corners result in a pricing that is absolutely outstanding and an overall printer quality that can, with a little effort, be at least really good, if not top shelf.


To calibrate a printer manually without any automation takes great patience. With the Anet A8, the procedure is very naked, bare metal and you probably need to repeat the steps several times before it's tuned in properly. There are excellent general calibration guides available online, but it is sometimes difficult to understand how the different procedures affect each other. A lot of the money you saved on purchase the Anet A8 shows up here, in time you spend to perform and understand calibration.


Being a clone with excellent heritage, the Anet A8 is a pretty good machine in basic form, but after assembly, further upgrades just feels like a natural continuation. And this is where A8 really shines. For a small sum of money, you can get a foot in the door with 3d printing and can from there on developing the hobby at your own pace and price range. There are lots of printable upgrades for the A8 and even more for its sibling clones that with a little challenge can be adapted to Anet. Do you want to upgrade firmware, mount a bed leveling probe or a sticky PEI sheet on your hotbed? Do you want to remotely control your machine with an OctoPrint module or build an enclosure? The possibilities are endless with upgrades.

The Anet A8 can become the first printer that you quickly move on from after your first taste of 3d printing and are ready to take the plunge with something more expensive. Or you could continue to build and upgrade this machine far into the future. Building and operating an Anet A8 is a highly educational experience that will take the user through a curious labyrinth of soft and hardware challenges. A truly entertaining path that is likely to imprint a lasting passion for the 3D printer hobby. Get one with a coupon at:
Anet A8: http://www.gearbest.com/3d-printers-3d-printer-kits/pp_343643.html Coupon code: "A8SUPER" / $149.89 (will expire on Aug, 31th) Category (Electrical & Tools ): http://www.gearbest.com/electrical-tools-c_11347/show.html?odr=trending Coupon code: "GBTE" / 12% OFF

Sunday, August 20, 2017

Area Of Two Intersecting Circles


function Area_Of_Two_Intersecting_Circles(P1, P2,P1r,P2r) =
let(p1 = P1r * P1r,p2 = P2r * P2r )
(PI*p1+PI*p2)-
(
let(d = max(1e-32,norm(P2 -  P1)))
(d >= P1r + P2r) ?0:
d < abs(P2r - P1r)?PI * min(p1, p2):    
let( x = (p1 - p2 + d * d) / (2 * d),
z = x * x,  y = sqrt(p1 - z)) 
p1 * asin(y / P1r)/57.2958 + p2 * 
     asin(y / P2r)/57.2958 - y * 
     (x + sqrt(z + p2 - p1))             );
////////////////////////////////////////////////
p1=rands(0,40,2);
p2=rands(0,40,2);
r1=rands(1,20,1)[0];
r2=rands(1,20,1)[0];

echo(str(" Area 1 : ",PI*r1*r1," "));
echo(str(" Area 2 : ",PI*r2*r2," "));
echo(str(" Area ∑ : ",PI*r1*r1+PI*r2*r2)  );
echo(str(" Area  I : ",Area_Of_Two_Intersecting_Circles(p1,p2,r1,r2)));

linear_extrude(1) union(){
translate(p1)circle(r1,$fn=50);
translate(p2)circle(r2,$fn=50);
}
if(  norm(p2 -  p1)< r1 + r2 )color("red")linear_extrude(1.01)
intersection(){
translate(p1)circle(r1,$fn=50);
translate(p2)circle(r2,$fn=50);
}

 

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);
 

Wednesday, August 16, 2017

Randomly Shuffle A List

Put Items of a list in random sequence.

Deck=["Ace of Spades","Two of Spades","Three of Spades",
"Four of Spades","Five of Spades","Six of Spades","Seven of Spades",
"Eight of Spades","Nine of Spades","Ten of Spades","Jack of Spades",
"Queen of Spades","King of Spades","Ace of Hearts","Two of Hearts",
"Three of Hearts","Four of Hearts","Five of Hearts","Six of Hearts",
"Seven of Hearts","Eight of Hearts","Nine of Hearts","Ten of Hearts",
"Jack of Hearts","Queen of Hearts","King of Hearts","Ace of Clubs",
"Two of Clubs","Three of Clubs","Four of Clubs","Five of Clubs",
"Six of Clubs","Seven of Clubs","Eight of Clubs","Nine of Clubs",
"Ten of Clubs","Jack of Clubs","Queen of Clubs","King of Clubs",
"Ace of Diamonds","Two of Diamonds","Three of Diamonds",
"Four of Diamonds","Five of Diamonds","Six of Diamonds",
"Seven of Diamonds","Eight of Diamonds","Nine of Diamonds",
"Ten of Diamonds","Jack of Diamonds","Queen of Diamonds",
"King of Diamonds"];

echo( shuffle(Deck));
function shuffle(il,repeat=2)=len(il)<=1?il:
let(l=repeat>0?shuffle(il,repeat-1):il, p=split(l))
round(rands(0,2,1)[0])==0?
concat( shuffle(p[0]),shuffle(p[1])):
concat( shuffle(p[1]),shuffle(p[0]));

function split(l)=[
[for(i=[0:2:len(l)-1])l[i]],
[for(i=[1:2:len(l)-1])l[i]]]  ;
 

Monday, August 14, 2017

Recursive For Loop Workaround

State can be a singel variable or a vector of variables


echo(rfor (50,10,-10,[0,1]));

function rfor(i,to,stepsize=1,state)=
abs(i-to)<abs(stepsize)?/* are there space left to take next step */
state :  /* if done return state or what ever value you like*/
let(newstate=myFunction(state,i ))
rfor(i+stepsize,to,stepsize,newstate) // call next recursive step
;

/*your code here, reassign state as you like */
function myFunction (state,i)=  [state[0]+sqrt(i),state[1]];
 

Saturday, August 12, 2017

True/False Dice

Random true/false value

function dice()=round(rands(1,2,1)[0])==1?false:true;

 

Thursday, August 10, 2017

Volume Of A Cone By Radius And Height



function Volume_Of_A_Cone_By_Radius_And_Height(r,h )= 
    PI*r*r*h*(1/3);
 

Wednesday, August 9, 2017

0 - 1 Remapping Functions: Arc1

/* remapping functions */


for(i=[-0:1/160:1])translate([i,0])square([1/160,  (arc1(  (i)))]);
    function arc1 (x,n=0) = let(a= n>0? arc1(x,(n-1)):x) clamp(sqrt(1-(1-a)*(1-a)));
    function clamp(a, b = 0, c = 1) = min(max(a, b), c);
 

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);
 

Wednesday, August 2, 2017

Tuesday, August 1, 2017

3D Printer review

I currently has a Anet A8 home for review.
Very affordable, good looking and Straightforward assembly.
Updates on operations will be posted as soon as possible. 


 

Monday, July 31, 2017

Random RGB Color

Generates a random rgb color value to be used by color();

function rndc() = rands(0, 1, 3) ;
 

Thursday, July 27, 2017

Area Of A Circle Segment By Angle

 function Area_Of_A_Circle_Segment_By_Angle(r,c)=
(r*r)/2*(PI/180*c-sin(c));
 

Tuesday, July 25, 2017

Area Of A Circle Segment By Height



function Area_Of_A_Circle_Segment_By_Height(r,h)=
    (r*r)*acos((r-h)/r)*((2*PI)/360)-(r-h)*sqrt((2*r*h)-(h*h));
 

Sunday, July 23, 2017

Arc Length By Angle


function Arc_Length_By_Angle(radius,central_angle)=
2*PI*radius*(central_angle/360);
 

Friday, July 21, 2017

Area Circle Sector By Arc Length



function Area_Circle_Sector_By_Arc_Length(radius,length)=
(radius*length)/2;

 

Wednesday, July 19, 2017

Perimeter Of A Circle Sector By Angle

function Perimeter_Of_A_Circle_Sector_By_Angle (radius,central_angle)=
central_angle<360?
2*PI*radius*(central_angle/360)+(2*r)
:2*PI*radius*(central_angle/360);

Monday, July 17, 2017

Area Of A Circle Sector By Angle


function Area_Circle_Sector_By_Angle(radius,central_angle)=
       PI*radius*radius*(central_angle/360);


 

Saturday, July 15, 2017

Radius A Regular Polygon By Inradius And N



function Radius_A_Regular_Polygon_By_Inradius_And_N(r,N)=r/(cos/(180/N));

 

Friday, July 14, 2017

List Lerp

Linear interpolation over the items in a list

list=[[1,6],[3,5],[5,3],[1,2],[0,6]];

for(x=[0.01:0.05:4]){
echo(listlerp (list,x));
translate(listlerp (list,x))sphere(0.1);}

function listlerp (l,I)=let(
f=len(l)-1,start=max(0,min(f,floor(I))),
end=max(0,min(f,ceil(I))),bias=I%1) 
(l[end]* bias + l[start] * (1 - bias));

 

Thursday, July 13, 2017

Radius Of Equilateral Triangle By Side



function Radius_Of_Equilateral_Triangle_By_Side (A)=A/(2*sin/(180/3));

Wednesday, July 12, 2017

Volume Of A Pyramid By Sides And Height



function Volume_Of_A_Pyramid_By_Sides_And_Height(A,B,h )= 
    A*B*h*(1/3);
 

Tuesday, July 11, 2017

Monday, July 10, 2017

Volume Of A Ellipsoid By Radius



function Volume_Of_A_Ellipsoid_By_Radius(r1,r2,r1 )=
    (4/3)*Pi* r1* r2* r3 ;
 

Sunday, July 9, 2017

Saturday, July 8, 2017

Mystic Scribbles

Generate a page of random nonsense scribbles in the style of mystic manuscript.

for (rows=[0:20])
{My_poly_line=make_points(120- round(rnd(20)));
translate([rnd(20),rows*27])polyline(My_poly_line);
}
module sline(p1, p2 ,width=0.6,s=12) {
if(abs(p1.x-p2.x)>abs(p1.y-p2.y)){
for(i=[-1/s:1/s:1+1/s]) 
line(xlerp(p1,p2,i),xlerp(p1,p2,i+1/s),width);}
else{for(i=[0:1/s:1-1/s]) 
line(ylerp(p1,p2,i),ylerp(p1,p2,i+1/s),width);}}

module line(p1, p2 ,width=0.3) {
 hull() {        
translate(p1) rotate(45)scale([3,0.1]) circle(width);
translate(p2) rotate(45)scale([3,0.1]) circle(width);    }}


module polyline(p) {for(i=[0:max(0,len(p)-2)])
    if(round(rnd(0.53))==0)sline(p[i],p[i+1]);}
function smooth_curve(a) =
let (b = clamp(a))(b * b * (3 - 2 * b));

function clamp(a, b = 0, c = 1) = min(max(a, b), c);
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
function xlerp(start, end, i) =
     [lerp(start.x,end.x,smooth_curve(i)),lerp(start.y,end.y,i)];
function ylerp(start, end, i) =
     [lerp(start.x,end.x,i),lerp(start.y,end.y,smooth_curve(i))];
 
function make_points(j=10,l1=[-30,-10],l2=[30,10])= 
     ([for(i=[1:j])[
rnd(l1.x,l2.x)/4+i*4,
rnd(l1.y,l2.y)]]);
function rnd(a = 1, b = 0, s = []) = 
  s == [] ? 
   (rands(min(a, b), max(   a, b), 1)[0]) 
  : 
   (rands(min(a, b), max(a, b), 1, s)[0])
  ; 


 

Friday, July 7, 2017

Volume Of A Prism By Base Heights



function Volume_Of_A_Prism_By_Base_Heights(A,h,H)=
    (1/2)*A*h*H;
 

Thursday, July 6, 2017

Volume Of A Prism By Sides Height



function Volume_Of_A_Prism_By_Sides_Height(A,B,C,H)=
    let(s=(a+b+c)/2) sqrt(abs(s*(s-a)*(s-b)*(s-c)))*H;
 

Wednesday, July 5, 2017

Area Of A Regular Polygon By Inradius And N



function Area_Of_A_Regular_Polygon_By_Inradius_And_N(r,N)= 
    r*r*N*tan(180/n);
 

Tuesday, July 4, 2017

Area Of A Equilateral Prism By Side Height



function Area_Of_A_Equilateral_Prism_By_Side_Height(A,H)=
    sqrt(3)/4 *(A*A) +A*H*3;
 

Monday, July 3, 2017

Area Of A Prism By Sides Height



function Area_Of_A_Prism_By_Sides_Height(A,B,C,H)=let(s=(a+b+c)/2) 
    2*sqrt(abs(s*(s-a)*(s-b)*(s-c)))+A*H+B*H+C*H;
 

Sunday, July 2, 2017

Area Of A Pyramid By Sides And Height




function Area_Of_A_Pyramid_By_Sides_And_Height(A,B,h )= 
    A*B+ 2*( (1/2)* A* (sqrt(h*h+(B/2)*(B/2))) )
       + 2*( (1/2)* B* (sqrt(h*h+(A/2)*(A/2))) );
 

Saturday, July 1, 2017

Area Of A Cone By Radius And Height



function Area_Of_A_Cone_By_Radius_And_Height(r,h )= 
    PI*r*r+ PI*r*sqrt(r*r+h*h);
 

Friday, June 30, 2017

Area Of A Cylinder By Radius And Height



function Area_Of_A_Cylinder_By_Radius_And_Height(r,h )= 
    2*(PI*r*r)+ 2*PI*r*h;
 

Wednesday, June 28, 2017

Area Of A Ellipsoid By Radius

Approximation

function Area_Of_A_Ellipsoid_By_Radius(r1,r2,r3 )=  
    4 * PI * pow(((r1*1.6075*r2*1.6075 + r1*1.6075*r3*1.6075
    + r2*1.6075*r3*1.6075)/3),1/1.6075);
 

Tuesday, June 27, 2017

Monday, June 26, 2017

Area Of A Cuboid By Sides



function Area_Of_A_Cuboid_By_Sides(A,B,C)=2*(A*B+A*C+C*B);



 

Sunday, June 25, 2017

Area Of A Irregular Polygon By Points



function  Area_Of_A_Irregular_Polygon_By_Points(points, i=1) =
    let(
    area = (points [i-1].x+points[i].x) * (points[i-1].y-points[i].y))
    i<len(points)?
    area/2 +Area_Of_A_Irregular_Polygon_By_Points(points, i+1) 
    :(points [i-1].x+points[0].x) * (points[i-1].y-points[0].y)/2; 

Saturday, June 24, 2017

Fictional Latin Name Generator

Generate made up latin sounding scientific names.


name = Name_Me();
echo(name);

function Name_Me() = str(
  prefyx1[intrnd(len(prefyx1))],
  suffyx1[ intrnd(len(suffyx1))],
  " ",
  prefyx2[intrnd(len(prefyx2))],
  suffyx2[intrnd(len(suffyx2))]);

function intrnd(a = 0,b = 1) = round((rands(min(a,b),max(a,b),1)[
  0]));
prefyx1 = ["Porodys","Folcam","Cmyd","Prct","Tit","Sog","Prat",
  "Broch","Hidr","Chymch","Spernaph","Lic","Cov","Ol","Ton",
  "Lotr","Psytt","Akop","Nirnec","Gar","Desnad","Gollym",
  "Av","Ephen","Lyss","Pmys","Thil","Helag","Dran","Glyr",
  "Roph","Achat","Phos","Con","Nelaps","Ochot","Struth",
  "Ysapt","Peron","Plotom","Cript","Borb","Vulp","Nesacr",
  "Corch","Log","Sinph","Oepic","Dosip","Banb","Nyr","Pamg",
  "Denasp","Pholomger","Lucom","Ppad","Tryd","Erithr","Pomth",
  "Rhymac","Nomdr","Nocr","Chonoel","Electr","Hypp","Scarp",
  "Coc","Chlar","Squol","Hinem","Phicad","Pov","Caroc",
  "Pstr","Vor","Freg","Cerot","Lep","Tetroad","Onb","Aryal",
  "Meaf","Pigasc","Gerb","Dyan","Holych","Astr","Enid",
  "Lept","Teuth","Om","Gymglin","Dypt","Heleyap","Arict",
  "Munyd","Rom","Ymdr","Chal","Stryg","Negopt","Coyn",
  "Pelec","Phisygm","Crac","Boloem","Vyv","Halath","Syn",
  "Chelam","Rhymad","Syluryf","Bas","Popylyam","Eud","Cyrr",
  "Pr","Tragl","Goleac","Demdrabr","Pryst","Nuroem","Serp",
  "Pratar","Cost","Lusc","Lon","Oylur","Tochig","Sorcaph",
  "Buf","Chlon","Sphem","Hil","Phac","Porol","Caleapt","Prd",
  "Urapl","Farnyc","Cephol","Leamtap","Olcel","Tors","Pteran",
  "Aphys","Mos","Gul","Gekkam","Dycer","Recurv","Limx",
  "Adab","Heter","Cett","Dim","Laphal","Tren","Pp","Pogur",
  "Ereth","Ner","Copr","Loc","Oct","Suryc","Cigm","Net",
  "Bys","Pag","Phoeth","Doubemt","Pelaph","Pyc","Cracad",
  "Vanb","Bolsem","Och","Stryx","Yms","Neleogr","Coll",
  "Romg","Asteal","Micter","Helad","Gyr","Droc","Ator","Emh",
  "Lynul","Threskyarm","Omg","Pseud","Set","Nust","Prac",
  "Goll","Dern","Coud","Lutr","Lorv","Oj","Tolp","Cyvett",
  "Prochm","Turs","Poroch","Eupt","Han","Chyl","Snyl",
  "Rupyc","Cet","Br","Poss","Phaemyc","Prv","Urs","Canmach",
  "Scyur","But","Hilab","Chlonid","Sphir","Frot","Cer",
  "Leap","Oll","Tox","Arc","Mectaphr","Pigac","Ginmyd",
  "Geach","Dyd","Rhymc","Adac","Noc","Hyer","Choetad",
  "Echym","Pom","Eryth","Laxad","Ppot","Trych","Nesabotr",
  "Cor","Locert","Oeg","Sus","Dos","Blott","Nycrac","Phol",
  "Delph","Panoc","Cat","Ptel","Vesp","Pec","Phis","Negod",
  "Coel","Yguom","Stegast","Chaer","Fum","Eleuther","Lepys",
  "Tetroam","Onphypr","Mephr","Armytharh","Ronph","Hel",
  "Gerr","Dypl","Pop","Es","Cychl","Pptem","Trach",
  "Rhymacer","Nomnuth","Nomt","Hyppap","Chel","Eleph",
  "Ocomth","Cos","Logemarh","Oyl","Simc","Sep","Nal","Lemn",
  "Pryam","Demdrab","Phoran","Pog","Eq","Lyt","Trogel",
  "Pmth","Rott","Phoscal","Actap","Henyg","Gaph","Dug",
  "Lobr","Ocym","Sul","Neph","Com","Paec","Iso","Phocach",
  "Cuam","Bett","Xemap","Groid","Gov","Dyc","Amysc","Momd",
  "Pter","Top","Olc","Len","Ceb","Fel","Caccym","Prctac",
  "Urach","Porodax","Phosnot","Soyn","Bub","Hidrad","Chyrapt",
  "Sph"];
prefyx2 = ["Vulp","Bym","Phis","Nol","Escul","Yguom","Splemd",
  "Delyc","Corch","Grouer","Nuscul","Rydyb","Mad","Lotr",
  "Tybet","Onphyb","Umyc","Otr","Arm","Lup","Scomd","Cat",
  "Danest","Herc","Pumct","Nelom","But","Oeg","Fusc","Olb",
  "Silv","Jub","Farst","Ogoss","Sun","Fonyl","Ymdr","Ocomth",
  "Barm","Papul","Nor","Goiom","Chris","Rubec","Cyv","Leuc",
  "Aedyp","Tragl","Or","Cumyc","Syn","Electr","Harr","Vytul",
  "Borb","Nocrac","Pord","Quogg","Nym","Conelap","Gyg","Olp",
  "Tour","Mott","Log","Cicl","Sph","Hidrach","Eq","Valyt",
  "Ber","Pot","Nogorh","Tenpar","Onblirh","Mghetymh","Lomyg",
  "Rott","Nul","Copuc","Glon","Ar","Lat","Tip","Org","Camc",
  "Rupyc","Dymg","Hobrapt","Bub","Ocutar","Fulg","Pryn",
  "Noxyn","Jocks","Foscyc","Suryc","Oj","Pyct","Nomd","Zerd",
  "Byr","Streps","Den","Euric","Ynper","Omg","Tac","Lept",
  "Abscur","Ras","Cym","Grunm","Cott","Piger","Neph","Coff",
  "Gomget","Olc","Tomg","Fromc","Kanad","Pom","Limx","Vym",
  "Oxelr","Draned","Hyrc","Sciph","Crac","Spylag","Dorw",
  "Yb","Ern","Vulg","Byc","Potog","Nogell","Myv","Lorv",
  "Tetr","Onaiems","Retyc","Nur","Cor","Gar","Lun","Arc",
  "Umdul","Os","Sop","Carb","Dyph","Horr","Fer","Jahmst",
  "Ol","Susp","Nel","Praciam","Buf","Odel","Fur","Plotirh",
  "Nomdt","Obel","Bysam","Sulfur","Derb","Folcam","Ymd",
  "Tryd","Omtyp","Accyd","Less","Rasn","Cyrr","Grip","Cemtr",
  "Vytt","Boctr","Pop","No","Dug","Haffn","Cucull","Serv",
  "Tor","Olysn","Zig","Loev","Pign","Nyd","Conel","Geaffr",
  "Bymt","Zebr","Nom","Pyc","Delph","Str","Eurap","Ymn",
  "Lemn","Mavoeomgl","Tygr","Omot","Rabust","Mos","Cotesb",
  "Grev","Poln","Lutr","Ursym","Our","Hern","Dars","Scr",
  "Cryst","Put","Nemd","Cob","Ofr","Goll","Toj","Olbyv",
  "Frog","Kymg","Meb","Logatr","Tox","Olt","Rodyot","Namoch",
  "Gygomt","Cop","Vyverr","Bemgol","Porv","Nocul","Eleg",
  "Hunb","Samd","Cuv","Sunotr","Ogyl","Fosc","Yr","Broch",
  "Ocul","Ful","Noxyll","Parc","Trumc","Orct","Amc","Lyber",
  "Dyehl","Gul","Ruf","Calch"];
suffyx1 = ["ebus","echus","ecto","edeydoe","eydoe","eyradam",
  "elo","eles","elys","ello","ellydoe","elame","elphys",
  "elus","enus","emtes","emtrus","emus","ea","eamydoe",
  "epholymoe","ero","erculo","erda","erydoe","eryx","erno",
  "eraptero","eras","erro","erto","erus","es","eter","eus",
  "eutes","yo","yolys","yomus","yos","ycetus","ychthis",
  "ycalo","yctys","ydo","ydoe","ydeo","yfer","yfero",
  "yfarne","ygotar","yido","yidoe","yifarnes","ylyo","ylydoe",
  "yllo","yllymoe","yllus","ylatys","ylus","amtymoe","amix",
  "apex","aphogo","apharus","aphris","apydoe","apado",
  "apracto","aps","ojoa","ole","olys","olus","onolys",
  "onbulus","omchyoto","omger","omymoe","omto","omthydoe",
  "omtulus","omus","oam","ophymoe","ophus","opro","optero",
  "orctas","ordus","orhymus","ory","oryo","oradam","os",
  "ostes","ostas","oto","othus","otydoe","otymo","otus",
  "ourus","ovyo","eoster","aotus","athryx","atydoe","atrytam",
  "auotto","aumgo","ax","azao","uo","uoryus","oimus","ois",
  "ulo","uno","ur","uro","urgo","urydoe","apsys","aptero",
  "apterus","apus","ar","ardoto","arhymus","aryo","arnes",
  "arus","arix","asourus","asteydoe","astano","atonus",
  "atheryun","oco","ocol","ochyo","ochrus","ocyme","ocmo",
  "ocus","oe","oeydoe","oenus","oemo","oemydoe","oetes",
  "offo","oylurus","oyus","ojo","urmyx","uraydeo","urus",
  "us","uto","uus","iotys","idro","idrydoe","yimy","ilox",
  "ilus","imchus","ime","inmys","iam","ipelno","ipharus",
  "ipyus","iptes","iptulo","irmo","isadam","istano","iuro",
  "iurus","ymo","ymoe","ymy","ymyo","ymydyo","ymaydeo",
  "ymus","ya","yaydeo","yames","yamymoe","yaps","ypedyo",
  "yry","yrastro","yrus","ys","yscus","ystaydeo","ythecus",
  "ythydoe","ythades","ythryx","ytys","yttocus","yus","yzam",
  "lassus","a","abyus","aconpo","aconpus","acebus","ach",
  "achelis","achaerus","adoctilus","adeo","adectus","adydoe",
  "adam","adamtus","adites","aepus","aerus","agole","aydeo",
  "ayleus","ays","alogus","ano","anarpho","am","amo","amg",
  "amgyoe","amyo","amyx","amto","amtydoe"];
suffyx2 = ["amix","apus","ar","aryus","armys","as","astroto",
  "astrys","asus","atoto","atys","auro","auxyi","ax","ayi",
  "azao","uo","uca","ues","oimus","otycus","otar","yomus",
  "yorys","yos","yotun","yotus","yblys","yco","yceps",
  "yceras","ycho","yculus","ycus","ydus","yems","yemsys",
  "yer","yes","ygemyus","yi","ylys","yllo","ylus","ymo",
  "ymeo","ymyi","ymaso","ymun","ymus","ymx","yal","yaso",
  "ys","yscy","yscus","ysyi","ytynus","ytys","yus","yzyi",
  "a","acane","ades","ady","adytus","adites","aemsys","afo",
  "aydes","aldty","aleuco","alaphus","alar","am","amoe",
  "ame","amy","amycus","amyi","otroe","otto","otu","otun",
  "otus","oun","oiomus","eo","eotus","ol","olyo","olys",
  "ollus","olumgo","olus","onpus","om","omdus","omy",
  "omycus","oms","omus","opro","ordolys","oryo","oryos",
  "orymyo","orys","oryus","orun","orus","os","ospys","oster",
  "otolo","iurus","ectun","eemsys","eyomo","elyo","ellus",
  "emgey","ems","emsys","emtolys","emteus","emtrys","emtus",
  "ea","epholus","er","ero","erery","ereus","ery","eryo",
  "ersus","erus","es","etto","etty","eus","yocus","yoe",
  "ulo","ulorys","uloto","ules","ulaso","ulus","un","umdus",
  "urmyx","uramg","us","uto","uus","iomus","yi","imchas",
  "ithrus","ocol","octilo","ocu","oeo","oemo","oerys","oeus",
  "ogrus","oyco","oycus","ojo"];