13 |
|
|
14 |
|
double |
15 |
|
fdot( /* return the dot product of two vectors */ |
16 |
< |
register FVECT v1, |
17 |
< |
register FVECT v2 |
16 |
> |
const FVECT v1, |
17 |
> |
const FVECT v2 |
18 |
|
) |
19 |
|
{ |
20 |
|
return(DOT(v1,v2)); |
23 |
|
|
24 |
|
double |
25 |
|
dist2( /* return square of distance between points */ |
26 |
< |
register FVECT p1, |
27 |
< |
register FVECT p2 |
26 |
> |
const FVECT p1, |
27 |
> |
const FVECT p2 |
28 |
|
) |
29 |
|
{ |
30 |
|
FVECT delta; |
39 |
|
|
40 |
|
double |
41 |
|
dist2line( /* return square of distance to line */ |
42 |
< |
FVECT p, /* the point */ |
43 |
< |
FVECT ep1, |
44 |
< |
FVECT ep2 /* points on the line */ |
42 |
> |
const FVECT p, /* the point */ |
43 |
> |
const FVECT ep1, |
44 |
> |
const FVECT ep2 /* points on the line */ |
45 |
|
) |
46 |
|
{ |
47 |
< |
register double d, d1, d2; |
47 |
> |
double d, d1, d2; |
48 |
|
|
49 |
|
d = dist2(ep1, ep2); |
50 |
|
d1 = dist2(ep1, p); |
56 |
|
|
57 |
|
double |
58 |
|
dist2lseg( /* return square of distance to line segment */ |
59 |
< |
FVECT p, /* the point */ |
60 |
< |
FVECT ep1, |
61 |
< |
FVECT ep2 /* the end points */ |
59 |
> |
const FVECT p, /* the point */ |
60 |
> |
const FVECT ep1, |
61 |
> |
const FVECT ep2 /* the end points */ |
62 |
|
) |
63 |
|
{ |
64 |
< |
register double d, d1, d2; |
64 |
> |
double d, d1, d2; |
65 |
|
|
66 |
|
d = dist2(ep1, ep2); |
67 |
|
d1 = dist2(ep1, p); |
82 |
|
|
83 |
|
void |
84 |
|
fcross( /* vres = v1 X v2 */ |
85 |
< |
register FVECT vres, |
86 |
< |
register FVECT v1, |
87 |
< |
register FVECT v2 |
85 |
> |
FVECT vres, |
86 |
> |
const FVECT v1, |
87 |
> |
const FVECT v2 |
88 |
|
) |
89 |
|
{ |
90 |
|
vres[0] = v1[1]*v2[2] - v1[2]*v2[1]; |
95 |
|
|
96 |
|
void |
97 |
|
fvsum( /* vres = v0 + f*v1 */ |
98 |
< |
register FVECT vres, |
99 |
< |
register FVECT v0, |
100 |
< |
register FVECT v1, |
101 |
< |
register double f |
98 |
> |
FVECT vres, |
99 |
> |
const FVECT v0, |
100 |
> |
const FVECT v1, |
101 |
> |
double f |
102 |
|
) |
103 |
|
{ |
104 |
|
vres[0] = v0[0] + f*v1[0]; |
109 |
|
|
110 |
|
double |
111 |
|
normalize( /* normalize a vector, return old magnitude */ |
112 |
< |
register FVECT v |
112 |
> |
FVECT v |
113 |
|
) |
114 |
|
{ |
115 |
< |
register double len, d; |
115 |
> |
double len, d; |
116 |
|
|
117 |
|
d = DOT(v, v); |
118 |
|
|
119 |
< |
if (d <= FTINY*FTINY) |
119 |
> |
if (d == 0.0) |
120 |
|
return(0.0); |
121 |
|
|
122 |
< |
if (d <= 1.0+FTINY && d >= 1.0-FTINY) |
122 |
> |
if ((d <= 1.0+FTINY) & (d >= 1.0-FTINY)) { |
123 |
|
len = 0.5 + 0.5*d; /* first order approximation */ |
124 |
< |
else |
124 |
> |
d = 2.0 - len; |
125 |
> |
} else { |
126 |
|
len = sqrt(d); |
127 |
< |
|
128 |
< |
v[0] *= d = 1.0/len; |
127 |
> |
d = 1.0/len; |
128 |
> |
} |
129 |
> |
v[0] *= d; |
130 |
|
v[1] *= d; |
131 |
|
v[2] *= d; |
132 |
|
|
137 |
|
int |
138 |
|
closestapproach( /* closest approach of two rays */ |
139 |
|
RREAL t[2], /* returned distances along each ray */ |
140 |
< |
FVECT rorg0, /* first origin */ |
141 |
< |
FVECT rdir0, /* first direction (normalized) */ |
142 |
< |
FVECT rorg1, /* second origin */ |
143 |
< |
FVECT rdir1 /* second direction (normalized) */ |
140 |
> |
const FVECT rorg0, /* first origin */ |
141 |
> |
const FVECT rdir0, /* first direction (normalized) */ |
142 |
> |
const FVECT rorg1, /* second origin */ |
143 |
> |
const FVECT rdir1 /* second direction (normalized) */ |
144 |
|
) |
145 |
|
{ |
146 |
|
double dotprod = DOT(rdir0, rdir1); |
160 |
|
} |
161 |
|
|
162 |
|
|
161 |
– |
#if 0 |
162 |
– |
int |
163 |
– |
closestapproach( /* closest approach of two rays */ |
164 |
– |
RREAL t[2], /* returned distances along each ray */ |
165 |
– |
FVECT rorg0, /* first origin */ |
166 |
– |
FVECT rdir0, /* first direction (unnormalized) */ |
167 |
– |
FVECT rorg1, /* second origin */ |
168 |
– |
FVECT rdir1 /* second direction (unnormalized) */ |
169 |
– |
) |
170 |
– |
{ |
171 |
– |
double dotprod = DOT(rdir0, rdir1); |
172 |
– |
double d0n2 = DOT(rdir0, rdir0); |
173 |
– |
double d1n2 = DOT(rdir1, rdir1); |
174 |
– |
double denom = d0n2*d1n2 - dotprod*dotprod; |
175 |
– |
double o1o2_d1; |
176 |
– |
FVECT o0o1; |
177 |
– |
|
178 |
– |
if (denom <= FTINY) { /* check if lines are parallel */ |
179 |
– |
t[0] = t[1] = 0.0; |
180 |
– |
return(0); |
181 |
– |
} |
182 |
– |
VSUB(o0o1, rorg0, rorg1); |
183 |
– |
o1o2_d1 = DOT(o0o1, rdir1); |
184 |
– |
t[0] = (o1o2_d1*dotprod - DOT(o0o1,rdir0)*d1n2) / denom; |
185 |
– |
t[1] = (o1o2_d1 + t[0]*dotprod) / d1n2; |
186 |
– |
return(1); |
187 |
– |
} |
188 |
– |
#endif |
189 |
– |
|
190 |
– |
|
163 |
|
void |
164 |
|
spinvector( /* rotate vector around normal */ |
165 |
< |
FVECT vres, /* returned vector */ |
166 |
< |
FVECT vorig, /* original vector */ |
167 |
< |
FVECT vnorm, /* normalized vector for rotation */ |
168 |
< |
double theta /* left-hand radians */ |
165 |
> |
FVECT vres, /* returned vector (same magnitude as vorig) */ |
166 |
> |
const FVECT vorig, /* original vector */ |
167 |
> |
const FVECT vnorm, /* normalized vector for rotation */ |
168 |
> |
double theta /* right-hand radians */ |
169 |
|
) |
170 |
|
{ |
171 |
|
double sint, cost, normprod; |
172 |
|
FVECT vperp; |
173 |
< |
register int i; |
173 |
> |
int i; |
174 |
|
|
175 |
|
if (theta == 0.0) { |
176 |
|
if (vres != vorig) |
183 |
|
fcross(vperp, vnorm, vorig); |
184 |
|
for (i = 0; i < 3; i++) |
185 |
|
vres[i] = vorig[i]*cost + vnorm[i]*normprod + vperp[i]*sint; |
186 |
+ |
} |
187 |
+ |
|
188 |
+ |
double |
189 |
+ |
geodesic( /* rotate vector on great circle towards target */ |
190 |
+ |
FVECT vres, /* returned vector (same magnitude as vorig) */ |
191 |
+ |
const FVECT vorig, /* original vector */ |
192 |
+ |
const FVECT vtarg, /* vector we are rotating towards */ |
193 |
+ |
double t, /* amount along arc directed towards vtarg */ |
194 |
+ |
int meas /* distance measure (radians, absolute, relative) */ |
195 |
+ |
) |
196 |
+ |
{ |
197 |
+ |
FVECT normtarg; |
198 |
+ |
double volen, dotprod, sint, cost; |
199 |
+ |
int i; |
200 |
+ |
|
201 |
+ |
if (vres != vorig) |
202 |
+ |
VCOPY(vres, vorig); |
203 |
+ |
if (t == 0.0) |
204 |
+ |
return(VLEN(vres)); /* no rotation requested */ |
205 |
+ |
if ((volen = normalize(vres)) == 0.0) |
206 |
+ |
return(0.0); |
207 |
+ |
VCOPY(normtarg, vtarg); |
208 |
+ |
if (normalize(normtarg) == 0.0) |
209 |
+ |
return(0.0); /* target vector is zero */ |
210 |
+ |
dotprod = DOT(vres, normtarg); |
211 |
+ |
/* check for colinear */ |
212 |
+ |
if (dotprod >= 1.0-FTINY*FTINY) { |
213 |
+ |
if (meas != GEOD_REL) |
214 |
+ |
return(0.0); |
215 |
+ |
vres[0] *= volen; vres[1] *= volen; vres[2] *= volen; |
216 |
+ |
return(volen); |
217 |
+ |
} |
218 |
+ |
if (dotprod <= -1.0+FTINY*FTINY) |
219 |
+ |
return(0.0); |
220 |
+ |
if (meas == GEOD_ABS) |
221 |
+ |
t /= volen; |
222 |
+ |
else if (meas == GEOD_REL) |
223 |
+ |
t *= acos(dotprod); |
224 |
+ |
cost = cos(t); |
225 |
+ |
sint = sin(t); |
226 |
+ |
for (i = 0; i < 3; i++) |
227 |
+ |
vres[i] = volen*( cost*vres[i] + |
228 |
+ |
sint*(normtarg[i] - dotprod*vres[i]) ); |
229 |
+ |
|
230 |
+ |
return(volen); /* return vector length */ |
231 |
|
} |