summaryrefslogtreecommitdiff
path: root/src/lsq_rectilinear.mac
blob: cea35e14b69cc48305d7cd4e1f1fb4bca9e03980 (plain)
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
/*
 * rectilinear (pinhole) projection model with distortion correction
 */

/* switch to cartesian coordinates for nick rotation */
c_x : cos(m_nick) * cos(m_view - c_view)$
c_y : cos(m_nick) * sin(m_view - c_view)$
c_z : sin(m_nick)$

c_x_rot : cos(c_nick) * c_x$ + sin(c_nick) * c_z$
c_y_rot : c_y$
c_z_rot : -sin(c_nick) * c_x + cos(c_nick) * c_z$

/* back to spheric coordinates */
a_h : (\pi/2 - acos(c_z_rot))$
a_v : atan(c_y_rot / c_x_rot)$

/* angle over horizon in view direction */
a_h_dir : atan (tan (a_h) * sqrt(tan(a_v) ^2  + 1))$ 

x : tan(a_v)$
y : tan(-a_h_dir)$ 
x_rot : y * sin(c_tilt) + x * cos(c_tilt)+x0$
y_rot : y * cos(c_tilt) - x * sin(c_tilt)$

/* distortion correction */
d : x_rot ^ 2 + y_rot ^ 2$
dist_fact : d ^ 2 * k1 + d * k0$
x_dist : x_rot * (1 + dist_fact) * scale$
y_dist : y_rot * (1 + dist_fact) * scale$

/*
 * Some mangling for C code generation
 */

load("expr2c.mac")$

x_expand : trigexpand(x_dist)$
y_expand : trigexpand(y_dist)$

args: "double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick"$

expr2c("ProjectionRectilinear::mac_x", args, x_expand)$
expr2c("ProjectionRectilinear::mac_y", args, y_expand)$

expr2c("ProjectionRectilinear::mac_x_dc_view", args, diff(x_expand, c_view))$
expr2c("ProjectionRectilinear::mac_x_dc_nick", args, diff(x_expand, c_nick))$
expr2c("ProjectionRectilinear::mac_x_dc_tilt", args, diff(x_expand, c_tilt))$
expr2c("ProjectionRectilinear::mac_x_dscale", args, diff(x_expand, scale))$
expr2c("ProjectionRectilinear::mac_x_dk0", args, diff(x_expand, k0))$
expr2c("ProjectionRectilinear::mac_x_dk1", args, diff(x_expand, k1))$
expr2c("ProjectionRectilinear::mac_x_dx0", args, diff(x_expand, x0))$
expr2c("ProjectionRectilinear::mac_y_dc_view", args, diff(y_expand, c_view))$
expr2c("ProjectionRectilinear::mac_y_dc_nick", args, diff(y_expand, c_nick))$
expr2c("ProjectionRectilinear::mac_y_dc_tilt", args, diff(y_expand, c_tilt))$
expr2c("ProjectionRectilinear::mac_y_dscale", args, diff(y_expand, scale))$
expr2c("ProjectionRectilinear::mac_y_dk0", args, diff(y_expand, k0))$
expr2c("ProjectionRectilinear::mac_y_dk1", args, diff(y_expand, k1))$
expr2c("ProjectionRectilinear::mac_y_dx0", args, diff(y_expand, x0))$