| 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 |
|
d = 2.0 - len; |
| 125 |
|
} else { |
| 162 |
|
|
| 163 |
|
void |
| 164 |
|
spinvector( /* rotate vector around normal */ |
| 165 |
< |
FVECT vres, /* returned vector */ |
| 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 */ |
| 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 |
|
} |