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
|
include <design.scad>
include <helpers.scad>
include <body_config.scad>
// TODO: create 2 kinds of functions: zero-centered and
// globally positioned (respecting optical design and/or
// other variables)
// up to 0.7 inside measurement range, but can be bigger outside.
// non-ideal printing/manufacturing is also possible
laser_ray_thickness = 1;
module laser_beam(z_range = ($actualZBaseMm + $actualZRangeMm) * 2)
{
x = tan($laserAngleDegrees / 2) * z_range;
color("red", 0.1)
polygon([
[0, 0],
[x, z_range],
[-x, z_range]
]);
}
// create a body of laser with diameter `d` and
// length `l`.
// the ray starts at the origin
module laser_body(d = default_laser_d, l = default_laser_l, show_beam=true)
{
rotate([-90, 0, 0])
translate([0, 0, -l])
cylinder($fn = diameterToFn(d), d = d, h = l);
// visible ray
zBase = $actualZBaseMm;
farZ = zBase + $actualZRangeMm;
// non-valid
color("red", 0.15)
*polygon(
[[0, 0],
[$actualXStartMm / 2, zBase],
[-$actualXStartMm / 2, zBase]]);
// non-valid, should ignore laser pos
// TODO: visualize laser beam
color("red", 0.3)
*polygon(
[[$actualXStartMm / 2, zBase],
[-$actualXStartMm / 2, zBase],
[-$actualXEndMm / 2, farZ],
[$actualXEndMm / 2, farZ],]);
if (show_beam)
{
laser_beam();
}
}
*laser_body();
*laser_beam();
|