8double sinx[361], cosx[361], asin2sqx[1001];
14double dist2UTM(
double x1,
double y1,
double x2,
double y2)
16 double x, y, cy1, cy2, yt, xi, yi;
18 x = fabs(x1 - x2) / 2;
19 y = fabs(y1 - y2) / 2;
24 x = (1 - x) * sinx[(
int)xi] + x * sinx[((int)xi) + 1];
25 y = (1 - y) * sinx[(
int)yi] + y * sinx[((int)yi) + 1];
26 yt = fabs(y1 + P.SpatialBoundingBox[1]);
29 cy1 = (1 - cy1) * cosx[((
int)yi)] + cy1 * cosx[((int)yi) + 1];
30 yt = fabs(y2 + P.SpatialBoundingBox[1]);
33 cy2 = (1 - cy2) * cosx[((
int)yi)] + cy2 * cosx[((int)yi) + 1];
34 x = fabs(1000 * (y * y + x * x * cy1 * cy2));
37 y = (1 - x) * asin2sqx[((
int)xi)] + x * asin2sqx[((int)xi) + 1];
38 return 4 * EARTHRADIUS * EARTHRADIUS * y;
45 return dist2UTM(Households[a->hh].loc_x, Households[a->hh].loc_y, Households[b->hh].loc_x, Households[b->hh].loc_y);
48 x = fabs(Households[a->hh].loc_x - Households[b->hh].loc_x);
49 y = fabs(Households[a->hh].loc_y - Households[b->hh].loc_y);
50 if (P.DoPeriodicBoundaries)
52 if (x > P.in_degrees_.width_ * 0.5) x = P.in_degrees_.width_ - x;
53 if (y > P.in_degrees_.height_ * 0.5) y = P.in_degrees_.height_ - y;
66 return dist2UTM(P.in_cells_.width_ * fabs((
double)(l / P.nch)), P.in_cells_.height_ * fabs((
double)(l % P.nch)),
67 P.in_cells_.width_ * fabs((
double)(m / P.nch)), P.in_cells_.height_ * fabs((
double)(m % P.nch)));
70 x = P.in_cells_.width_ * fabs((
double)(l / P.nch - m / P.nch));
71 y = P.in_cells_.height_ * fabs((
double)(l % P.nch - m % P.nch));
72 if (P.DoPeriodicBoundaries)
74 if (x > P.in_degrees_.width_ * 0.5) x = P.in_degrees_.width_ - x;
75 if (y > P.in_degrees_.height_ * 0.5) y = P.in_degrees_.height_ - y;
90 if (P.in_cells_.width_ * ((
double)abs(m / P.nch - l / P.nch)) > PI)
92 if (m / P.nch > l / P.nch)
94 else if (m / P.nch < l / P.nch)
99 if (m / P.nch > l / P.nch)
101 else if (m / P.nch < l / P.nch)
104 if (m % P.nch > l % P.nch)
106 else if (m % P.nch < l % P.nch)
108 return dist2UTM(P.in_cells_.width_ * fabs((
double)(i / P.nch)), P.in_cells_.height_ * fabs((
double)(i % P.nch)),
109 P.in_cells_.width_ * fabs((
double)(j / P.nch)), P.in_cells_.height_ * fabs((
double)(j % P.nch)));
113 if ((P.DoPeriodicBoundaries) && (P.in_cells_.width_ * ((
double)abs(m / P.nch - l / P.nch)) > P.in_degrees_.width_ * 0.5))
115 if (m / P.nch > l / P.nch)
117 else if (m / P.nch < l / P.nch)
122 if (m / P.nch > l / P.nch)
124 else if (m / P.nch < l / P.nch)
127 if ((P.DoPeriodicBoundaries) && (P.in_degrees_.height_ * ((
double)abs(m % P.nch - l % P.nch)) > P.in_degrees_.height_ * 0.5))
129 if (m % P.nch > l % P.nch)
131 else if (m % P.nch < l % P.nch)
136 if (m % P.nch > l % P.nch)
138 else if (m % P.nch < l % P.nch)
141 x = P.in_cells_.width_ * fabs((
double)(i / P.nch - j / P.nch));
142 y = P.in_cells_.height_ * fabs((
double)(i % P.nch - j % P.nch));
143 if (P.DoPeriodicBoundaries)
145 if (x > P.in_degrees_.width_ * 0.5) x = P.in_degrees_.width_ - x;
146 if (y > P.in_degrees_.height_ * 0.5) y = P.in_degrees_.height_ - y;
148 return x * x + y * y;
156 l = (int)(a - Mcells);
157 m = (int)(b - Mcells);
159 return dist2UTM(P.in_microcells_.width_ * fabs((
double)(l / P.get_number_of_micro_cells_high())), P.in_microcells_.height_ * fabs((
double)(l % P.get_number_of_micro_cells_high())),
160 P.in_microcells_.width_ * fabs((
double)(m / P.get_number_of_micro_cells_high())), P.in_microcells_.height_ * fabs((
double)(m % P.get_number_of_micro_cells_high())));
163 x = P.in_microcells_.width_ * fabs((
double)(l / P.get_number_of_micro_cells_high() - m / P.get_number_of_micro_cells_high()));
164 y = P.in_microcells_.height_ * fabs((
double)(l % P.get_number_of_micro_cells_high() - m % P.get_number_of_micro_cells_high()));
165 if (P.DoPeriodicBoundaries)
167 if (x > P.in_degrees_.width_ * 0.5) x = P.in_degrees_.width_ - x;
168 if (y > P.in_degrees_.height_ * 0.5) y = P.in_degrees_.height_ - y;
170 return x * x + y * y;
174double dist2_raw(
double ax,
double ay,
double bx,
double by)
179 return dist2UTM(ax, ay, bx, by);
184 if (P.DoPeriodicBoundaries)
186 if (x > P.in_degrees_.width_ * 0.5) x = P.in_degrees_.width_ - x;
187 if (y > P.in_degrees_.height_ * 0.5) y = P.in_degrees_.height_ - y;
189 return x * x + y * y;
The basic unit of the simulation and is associated to a geographical location.