53 lines
1.4 KiB
OpenSCAD
53 lines
1.4 KiB
OpenSCAD
use <./vector.scad>
|
|
|
|
function _unwrap_x_half(original,unwrapped=[],offset=0)=
|
|
let(length=len(original))
|
|
let(half=(length-2)/2+1)
|
|
let(i=len(unwrapped))
|
|
let(prev=original[i-1])
|
|
let(cur=original[i])
|
|
let(dx=cur[0]-prev[0])
|
|
let(dz=cur[2]-prev[2])
|
|
let(new=[offset+sqrt(pow(dx,2)+pow(dz,2)),cur[1],0])
|
|
|
|
i < half ? _unwrap_x_half(original,concat(unwrapped,[new]),new[0]) : concat(unwrapped,[new]) ;
|
|
|
|
;
|
|
|
|
function _unwrap_x(p)=
|
|
let(length=len(p))
|
|
let(half=(length-2)/2+1)
|
|
let(first=_unwrap_x_half(p,[[p[0][0],p[0][1],0]],p[0][0]))
|
|
let(second=[
|
|
for( i = [len(first):length-1])
|
|
[p[length-i][0],p[i][1],0]
|
|
])
|
|
flatten_vec([first,second])
|
|
;
|
|
|
|
|
|
function _unwrap_y_half(original,unwrapped,offset,s)=
|
|
let(length=len(original))
|
|
let(half=(length-2)/2+1)
|
|
let(i=len(unwrapped))
|
|
let(prev=original[i-1])
|
|
let(cur=original[i])
|
|
let(dx=cur[0]-prev[0])
|
|
let(dy=cur[1]-prev[1])
|
|
let(dz=cur[2]-prev[2])
|
|
let(new=[cur[0],offset+s*sqrt(pow(dy,2)+pow(dz,2)),0])
|
|
|
|
i < half ? _unwrap_y_half(original,concat(unwrapped,[new]),new[1],s) : concat(unwrapped,[new]) ;
|
|
|
|
;
|
|
|
|
function _unwrap_y(p,s=1)=
|
|
let(length=len(p))
|
|
let(half=(length-2)/2+1)
|
|
let(first=_unwrap_y_half(p,[[p[0][0],p[0][1],0]],p[0][1],s))
|
|
let(second=[
|
|
for( i = [len(first):length-1])
|
|
[p[i][0],first[length-i][1],0]
|
|
])
|
|
flatten_vec([first,second])
|
|
;
|