-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcylindrical_image.scad
135 lines (114 loc) · 3.42 KB
/
cylindrical_image.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
cylindrical image
creates a partial cylindrical object using included data generated from a JPG file
to create a relief or intaglio ( as for a lithophane) surface
image file is generated by image_to_openscad.py
Kit Wallace March 2015
Code licensed under the Creative Commons - Attribution - Share Alike license.
*/
function flatten(l) = [ for (a = l) for (b = a) b ] ;
function reverse(l) =
// reverse the elements of an array
[for (i=[1:len(l)]) l[len(l)-i]];
function reverse_faces(faces) =
[for (face = faces) reverse(face)];
function hadamard(a,b) =
len(a)==len(b)
? [for (i=[0:len(a)-1]) a[i]*b[i]]
: [];
function scale_3(list,scale) =
let (mscale =
len(scale) == 3
? scale : [scale,scale,scale])
[for (p=list) hadamard(p,mscale)] ;
function vt(i,j,nx,ny) = i +j*nx ;
function vb(i,j,nx,ny) = nx*ny + i +j*nx;
function surface_faces (nx,ny) =
concat(
[for (i=[0:nx-2])
for (j=[0:ny-2])
[vt(i,j,nx,ny),
vt(i+1,j,nx,ny),
vt(i+1,j+1,nx,ny),
vt(i,j+1,nx,ny)]
],
[for (i=[0:nx-2])
for (j=[0:ny-2])
reverse(
[vb(i,j,nx,ny),
vb(i+1,j,nx,ny),
vb(i+1,j+1,nx,ny),
vb(i,j+1,nx,ny)
])
],
[for (i=[0:nx-2])
reverse(
[vt(i,0,nx,ny),
vt(i+1,0,nx,ny),
vb(i+1,0,,nx,ny),
vb(i,0,,nx,ny)
])
],
[for (i=[0:nx-2])
[vt(i,ny-1,nx,ny),
vt(i+1,ny-1,nx,ny),
vb(i+1,ny-1,nx,ny),
vb(i,ny-1,nx,ny)
]
],
[for (j=[0:ny-2])
[vt(0,j,nx,ny),
vt(0,j+1,nx,ny),
vb(0,j+1,nx,ny),
vb(0,j,nx,ny)]
],
[for (j=[0:ny-2])
reverse(
[vt(nx-1,j,nx,ny),
vt(nx-1,j+1,nx,ny),
vb(nx-1,j+1,nx,ny),
vb(nx-1,j,nx,ny)]
)
]
);
module cylinder_surface(height,surface,depth=1,degrees=360,thickness,relief) {
sign = relief ? +1 : -1;
nx= len(surface);
ny= len(surface[0]);
echo ("nx=",nx,"ny=",ny);
circumference= height* nx/ny * 360/degrees;
radius =circumference/(2* PI);
echo("height",height,"circumference",circumference,"radius",radius);
image_points = image_map(radius,height,nx,ny,surface,depth,degrees,sign);
clear_points =clear_map(radius-thickness,height,nx,ny,degrees);
faces=surface_faces(nx,ny);
polyhedron(points = concat(image_points,clear_points),
faces = faces);
};
function image_map(radius,height,nx,ny,surface,depth=1,degrees=360,sign) =
[for (j=[0:ny-1])
for (i=[0:nx-1])
let (eij= surface[i][j] * depth)
let(a = degrees * i/nx)
[(radius + sign* eij) * cos(a),
(radius + sign* eij) * sin(a),
height * (ny-1-j)/ny]
];
function clear_map(radius,height,nx,ny,degrees=360) =
[for (j=[0:ny-1])
for (i=[0:nx-1])
let(a = degrees * i/nx)
[radius * cos(a),
radius * sin(a),
height * (ny-1-j)/ny]
];
/* ------------------- main ------------------ */
include <alfredo2.scad>
echo(image_file);
cylinder_surface(
height=100,
surface=image_data,
depth=6,
degrees=90,
thickness=6,
relief=false);