|
@@ -10,17 +10,13 @@
|
10
|
10
|
* *
|
11
|
11
|
\**************************************/
|
12
|
12
|
|
13
|
|
-//$t = 0.15; // comment out during animation
|
|
13
|
+$t = 0.15; // comment out during animation!
|
|
14
|
+X = 0; Y = 1;
|
|
15
|
+L = 0; R = 1; F = 2; B = 3;
|
14
|
16
|
|
15
|
17
|
//
|
16
|
|
-// Mesh info and points
|
|
18
|
+// Sample Mesh - Replace with your own
|
17
|
19
|
//
|
18
|
|
-
|
19
|
|
-mesh_width = 200; // X Size in mm of the probed area
|
20
|
|
-mesh_height = 200; // Y Size...
|
21
|
|
-zprobe_offset = 0; // Added to the points
|
22
|
|
-NAN = 0; // Z to use for un-measured points
|
23
|
|
-
|
24
|
20
|
measured_z = [
|
25
|
21
|
[ -1.20, -1.13, -1.09, -1.03, -1.19 ],
|
26
|
22
|
[ -1.16, -1.25, -1.27, -1.25, -1.08 ],
|
|
@@ -30,6 +26,28 @@ measured_z = [
|
30
|
26
|
];
|
31
|
27
|
|
32
|
28
|
//
|
|
29
|
+// An offset to add to all points in the mesh
|
|
30
|
+//
|
|
31
|
+zadjust = 0;
|
|
32
|
+
|
|
33
|
+//
|
|
34
|
+// Mesh characteristics
|
|
35
|
+//
|
|
36
|
+bed_size = [ 200, 200 ];
|
|
37
|
+
|
|
38
|
+mesh_inset = [ 10, 10, 10, 10 ]; // L, F, R, B
|
|
39
|
+
|
|
40
|
+mesh_bounds = [
|
|
41
|
+ [ mesh_inset[L], mesh_inset[F] ],
|
|
42
|
+ [ bed_size[X] - mesh_inset[R], bed_size[Y] - mesh_inset[B] ]
|
|
43
|
+];
|
|
44
|
+
|
|
45
|
+mesh_size = mesh_bounds[1] - mesh_bounds[0];
|
|
46
|
+
|
|
47
|
+ // NOTE: Marlin meshes already subtract the probe offset
|
|
48
|
+NAN = 0; // Z to use for un-measured points
|
|
49
|
+
|
|
50
|
+//
|
33
|
51
|
// Geometry
|
34
|
52
|
//
|
35
|
53
|
|
|
@@ -45,6 +63,7 @@ alternation = 2; // direction change modulus (try it)
|
45
|
63
|
|
46
|
64
|
show_plane = true;
|
47
|
65
|
show_labels = true;
|
|
66
|
+show_coords = true;
|
48
|
67
|
arrow_length = 5;
|
49
|
68
|
|
50
|
69
|
label_font_lg = "Arial";
|
|
@@ -62,8 +81,8 @@ mean_value = (big_z + lil_z) / 2.0;
|
62
|
81
|
mesh_points_y = len(measured_z);
|
63
|
82
|
mesh_points_x = len(measured_z[0]);
|
64
|
83
|
|
65
|
|
-xspace = mesh_width / (mesh_points_x - 1);
|
66
|
|
-yspace = mesh_height / (mesh_points_y - 1);
|
|
84
|
+xspace = mesh_size[X] / (mesh_points_x - 1);
|
|
85
|
+yspace = mesh_size[Y] / (mesh_points_y - 1);
|
67
|
86
|
|
68
|
87
|
// At $t=0 and $t=1 scale will be 100%
|
69
|
88
|
z_scale_factor = min_z_scale + (($t > 0.5) ? 1.0 - $t : $t) * (max_z_scale - min_z_scale) * 2;
|
|
@@ -72,6 +91,8 @@ z_scale_factor = min_z_scale + (($t > 0.5) ? 1.0 - $t : $t) * (max_z_scale - min
|
72
|
91
|
// Min and max recursive functions for 1D and 2D arrays
|
73
|
92
|
// Return the smallest or largest value in the array
|
74
|
93
|
//
|
|
94
|
+function some_1D(b,i) = (i<len(b)-1) ? (b[i] && some_1D(b,i+1)) : b[i] != 0;
|
|
95
|
+function some_2D(a,j) = (j<len(a)-1) ? some_2D(a,j+1) : some_1D(a[j], 0);
|
75
|
96
|
function min_1D(b,i) = (i<len(b)-1) ? min(b[i], min_1D(b,i+1)) : b[i];
|
76
|
97
|
function min_2D(a,j) = (j<len(a)-1) ? min_2D(a,j+1) : min_1D(a[j], 0);
|
77
|
98
|
function max_1D(b,i) = (i<len(b)-1) ? max(b[i], max_1D(b,i+1)) : b[i];
|
|
@@ -98,36 +119,59 @@ function pos(x,y,z) = [x * xspace, y * yspace, z_scale_factor * (z - mean_value)
|
98
|
119
|
//
|
99
|
120
|
module point_markers(show_home=true) {
|
100
|
121
|
// Mark the home position 0,0
|
101
|
|
- color([0,0,0,0.25]) translate([1,1]) cylinder(r=1, h=z_scale_factor, center=true);
|
|
122
|
+ if (show_home)
|
|
123
|
+ translate([1,1]) color([0,0,0,0.25])
|
|
124
|
+ cylinder(r=1, h=z_scale_factor, center=true);
|
102
|
125
|
|
103
|
126
|
for (x=[0:mesh_points_x-1], y=[0:mesh_points_y-1]) {
|
104
|
|
- z = measured_z[y][x];
|
|
127
|
+ z = measured_z[y][x] - zadjust;
|
105
|
128
|
down = z < mean_value;
|
106
|
|
- translate(pos(x, y, z)) {
|
|
129
|
+ xyz = pos(x, y, z);
|
|
130
|
+ translate([ xyz[0], xyz[1] ]) {
|
|
131
|
+
|
|
132
|
+ // Show the XY as well as the Z!
|
|
133
|
+ if (show_coords) {
|
|
134
|
+ color("black")
|
|
135
|
+ translate([0,0,0.5]) {
|
|
136
|
+ $fn=8;
|
|
137
|
+ rotate([0,0]) {
|
|
138
|
+ posx = floor(mesh_bounds[0][X] + x * xspace);
|
|
139
|
+ posy = floor(mesh_bounds[0][Y] + y * yspace);
|
|
140
|
+ text(str(posx, ",", posy), 2, label_font_sm, halign="center", valign="center");
|
|
141
|
+ }
|
|
142
|
+ }
|
|
143
|
+ }
|
107
|
144
|
|
108
|
|
- // Label each point with the Z
|
109
|
|
- if (show_labels) {
|
|
145
|
+ translate([ 0, 0, xyz[2] ]) {
|
|
146
|
+ // Label each point with the Z
|
110
|
147
|
v = z - mean_value;
|
|
148
|
+ if (show_labels) {
|
111
|
149
|
|
112
|
|
- color(abs(v) < 0.1 ? [0,0.5,0] : [0.25,0,0])
|
113
|
|
- translate([0,0,down?-10:10]) {
|
|
150
|
+ color(abs(v) < 0.1 ? [0,0.5,0] : [0.25,0,0])
|
|
151
|
+ translate([0,0,down?-10:10]) {
|
114
|
152
|
|
115
|
|
- $fn=8;
|
116
|
|
- rotate([90,0])
|
117
|
|
- text(str(z), 6, label_font_lg, halign="center", valign="center");
|
|
153
|
+ $fn=8;
|
|
154
|
+ rotate([90,0])
|
|
155
|
+ text(str(z), 6, label_font_lg, halign="center", valign="center");
|
118
|
156
|
|
119
|
|
- translate([0,0,down?-6:6]) rotate([90,0])
|
120
|
|
- text(str(down ? "" : "+", v), 3, label_font_sm, halign="center", valign="center");
|
|
157
|
+ if (v)
|
|
158
|
+ translate([0,0,down?-6:6]) rotate([90,0])
|
|
159
|
+ text(str(down || !v ? "" : "+", v), 3, label_font_sm, halign="center", valign="center");
|
|
160
|
+ }
|
121
|
161
|
}
|
122
|
|
- }
|
123
|
162
|
|
124
|
|
- // Show an arrow pointing up or down
|
125
|
|
- rotate([0, down ? 180 : 0]) translate([0,0,-1])
|
126
|
|
- cylinder(
|
127
|
|
- r1=0.5,
|
128
|
|
- r2=0.1,
|
129
|
|
- h=arrow_length, $fn=12, center=1
|
130
|
|
- );
|
|
163
|
+ // Show an arrow pointing up or down
|
|
164
|
+ if (v) {
|
|
165
|
+ rotate([0, down ? 180 : 0]) translate([0,0,-1])
|
|
166
|
+ cylinder(
|
|
167
|
+ r1=0.5,
|
|
168
|
+ r2=0.1,
|
|
169
|
+ h=arrow_length, $fn=12, center=1
|
|
170
|
+ );
|
|
171
|
+ }
|
|
172
|
+ else
|
|
173
|
+ color([1,0,1,0.4]) sphere(r=1.0, $fn=20, center=1);
|
|
174
|
+ }
|
131
|
175
|
}
|
132
|
176
|
}
|
133
|
177
|
}
|
|
@@ -161,7 +205,7 @@ module tesselated_square(s, alt=false) {
|
161
|
205
|
* The simplest mesh display
|
162
|
206
|
*/
|
163
|
207
|
module simple_mesh(show_plane=show_plane) {
|
164
|
|
- if (show_plane) color(plane_color) cube([mesh_width, mesh_height, thickness]);
|
|
208
|
+ if (show_plane) color(plane_color) cube([mesh_size[X], mesh_size[Y], thickness]);
|
165
|
209
|
color(mesh_color)
|
166
|
210
|
for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2])
|
167
|
211
|
tesselated_square(grid_square(x, y));
|
|
@@ -171,30 +215,34 @@ module simple_mesh(show_plane=show_plane) {
|
171
|
215
|
* Subdivide the mesh into smaller squares.
|
172
|
216
|
*/
|
173
|
217
|
module bilinear_mesh(show_plane=show_plane,tesselation=tesselation) {
|
174
|
|
- if (show_plane) color(plane_color) translate([-5,-5]) cube([mesh_width+10, mesh_height+10, thickness]);
|
175
|
|
- tesselation = tesselation % 4;
|
176
|
|
- color(mesh_color)
|
177
|
|
- for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2]) {
|
178
|
|
- square = grid_square(x, y);
|
179
|
|
- if (tesselation < 1) {
|
180
|
|
- tesselated_square(square,(x%alternation)-(y%alternation));
|
181
|
|
- }
|
182
|
|
- else {
|
183
|
|
- subdiv_4 = subdivided_square(square);
|
184
|
|
- if (tesselation < 2) {
|
185
|
|
- for (i=[0:3]) tesselated_square(subdiv_4[i],i%alternation);
|
|
218
|
+ if (show_plane) color(plane_color) translate([-5,-5]) cube([mesh_size[X]+10, mesh_size[Y]+10, thickness]);
|
|
219
|
+
|
|
220
|
+ if (some_2D(measured_z, 0)) {
|
|
221
|
+
|
|
222
|
+ tesselation = tesselation % 4;
|
|
223
|
+ color(mesh_color)
|
|
224
|
+ for (x=[0:mesh_points_x-2], y=[0:mesh_points_y-2]) {
|
|
225
|
+ square = grid_square(x, y);
|
|
226
|
+ if (tesselation < 1) {
|
|
227
|
+ tesselated_square(square,(x%alternation)-(y%alternation));
|
186
|
228
|
}
|
187
|
229
|
else {
|
188
|
|
- for (i=[0:3]) {
|
189
|
|
- subdiv_16 = subdivided_square(subdiv_4[i]);
|
190
|
|
- if (tesselation < 3) {
|
191
|
|
- for (j=[0:3]) tesselated_square(subdiv_16[j],j%alternation);
|
192
|
|
- }
|
193
|
|
- else {
|
194
|
|
- for (j=[0:3]) {
|
195
|
|
- subdiv_64 = subdivided_square(subdiv_16[j]);
|
196
|
|
- if (tesselation < 4) {
|
197
|
|
- for (k=[0:3]) tesselated_square(subdiv_64[k]);
|
|
230
|
+ subdiv_4 = subdivided_square(square);
|
|
231
|
+ if (tesselation < 2) {
|
|
232
|
+ for (i=[0:3]) tesselated_square(subdiv_4[i],i%alternation);
|
|
233
|
+ }
|
|
234
|
+ else {
|
|
235
|
+ for (i=[0:3]) {
|
|
236
|
+ subdiv_16 = subdivided_square(subdiv_4[i]);
|
|
237
|
+ if (tesselation < 3) {
|
|
238
|
+ for (j=[0:3]) tesselated_square(subdiv_16[j],j%alternation);
|
|
239
|
+ }
|
|
240
|
+ else {
|
|
241
|
+ for (j=[0:3]) {
|
|
242
|
+ subdiv_64 = subdivided_square(subdiv_16[j]);
|
|
243
|
+ if (tesselation < 4) {
|
|
244
|
+ for (k=[0:3]) tesselated_square(subdiv_64[k]);
|
|
245
|
+ }
|
198
|
246
|
}
|
199
|
247
|
}
|
200
|
248
|
}
|
|
@@ -249,7 +297,7 @@ function subdivided_square(a) = [
|
249
|
297
|
|
250
|
298
|
//================================================ Run the plan
|
251
|
299
|
|
252
|
|
-translate([-mesh_width / 2, -mesh_height / 2]) {
|
|
300
|
+translate([-mesh_size[X] / 2, -mesh_size[Y] / 2]) {
|
253
|
301
|
$fn = 12;
|
254
|
302
|
point_markers();
|
255
|
303
|
bilinear_mesh();
|