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

No comments:

Post a Comment