Showing posts with label log. Show all posts
Showing posts with label log. Show all posts

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

Monday, May 22, 2017

Test if a number is a Fibonacci number

Test if a number is in the list of Fibonacci numbers.
The function is_fibonacci returns a vector [true/false,place],
Usage: 



for (i = [0: 100])
  echo(i, ":", is_fibonacci(i));


function is_fibonacci(N) =
let (
  i = floor(log(N * sqrt(5)) / log((1 + sqrt(5)) / 2) + 0.5),
  n = floor(pow((1 + sqrt(5)) / 2, i) / sqrt(5) + 0.5),
  place = (n == N) ? i : -1)
[(n == N), place];