47 if (ax >
x+
w)
return 0;
49 if (ay >
y+
h)
return 0;
107 Point Dv = vel1-vel2;
109 if (Dv.
x || Dv.
y || Dv.
z)
110 t = -1 * (Dv*D) / (Dv*Dv);
157 result.
x = (float) ((m.
elem[0][0] *
x) + (m.
elem[1][0] *
y) + (m.
elem[2][0] *
z));
158 result.
y = (float) ((m.
elem[0][1] *
x) + (m.
elem[1][1] *
y) + (m.
elem[2][1] *
z));
159 result.
z = (float) ((m.
elem[0][2] *
x) + (m.
elem[1][2] *
y) + (m.
elem[2][2] *
z));
172 Point Dv = vel1-vel2;
174 if (Dv.
x || Dv.
y || Dv.
z)
175 t = -1 * (Dv*D) / (Dv*Dv);
241 return *
this = *
this * m;
264 inline void swap_elem(
double& a,
double& b) {
double t=a; a=b; b=t; }
282 double sr = sin(roll);
283 double cr = cos(roll);
284 double sp = sin(pitch);
285 double cp = cos(pitch);
286 double sy = sin(yaw);
287 double cy = cos(yaw);
295 elem[0][0] = a*e[0][0] + b*e[1][0] + c*e[2][0];
296 elem[0][1] = a*e[0][1] + b*e[1][1] + c*e[2][1];
297 elem[0][2] = a*e[0][2] + b*e[1][2] + c*e[2][2];
299 a = cp*-sr + sp*sy*cr;
300 b = cp* cr + sp*sy*sr;
303 elem[1][0] = a*e[0][0] + b*e[1][0] + c*e[2][0];
304 elem[1][1] = a*e[0][1] + b*e[1][1] + c*e[2][1];
305 elem[1][2] = a*e[0][2] + b*e[1][2] + c*e[2][2];
307 a = -sp*-sr + cp*sy*cr;
308 b = -sp* cr + cp*sy*sr;
311 elem[2][0] = a*e[0][0] + b*e[1][0] + c*e[2][0];
312 elem[2][1] = a*e[0][1] + b*e[1][1] + c*e[2][1];
313 elem[2][2] = a*e[0][2] + b*e[1][2] + c*e[2][2];
321 double s = sin(roll);
322 double c = cos(roll);
324 double e00 =
elem[0][0];
325 double e01 =
elem[0][1];
326 double e02 =
elem[0][2];
327 double e10 =
elem[1][0];
328 double e11 =
elem[1][1];
329 double e12 =
elem[1][2];
331 elem[0][0] = c*e00 + s*e10;
332 elem[0][1] = c*e01 + s*e11;
333 elem[0][2] = c*e02 + s*e12;
335 elem[1][0] = -s*e00 + c*e10;
336 elem[1][1] = -s*e01 + c*e11;
337 elem[1][2] = -s*e02 + c*e12;
345 double s = sin(pitch);
346 double c = cos(pitch);
348 double e10 =
elem[1][0];
349 double e11 =
elem[1][1];
350 double e12 =
elem[1][2];
351 double e20 =
elem[2][0];
352 double e21 =
elem[2][1];
353 double e22 =
elem[2][2];
355 elem[1][0] = c*e10 + s*e20;
356 elem[1][1] = c*e11 + s*e21;
357 elem[1][2] = c*e12 + s*e22;
359 elem[2][0] = -s*e10 + c*e20;
360 elem[2][1] = -s*e11 + c*e21;
361 elem[2][2] = -s*e12 + c*e22;
372 double e00 =
elem[0][0];
373 double e01 =
elem[0][1];
374 double e02 =
elem[0][2];
375 double e20 =
elem[2][0];
376 double e21 =
elem[2][1];
377 double e22 =
elem[2][2];
379 elem[0][0] = c*e00 - s*e20;
380 elem[0][1] = c*e01 - s*e21;
381 elem[0][2] = c*e02 - s*e22;
383 elem[2][0] = s*e00 + c*e20;
384 elem[2][1] = s*e01 + c*e21;
385 elem[2][2] = s*e02 + c*e22;
390 inline int sign(
double d) {
return (d >= 0); }
397 yaw = asin(-
elem[0][2]);
399 roll = asin(
elem[0][1] / cy);
400 pitch = asin(
elem[1][2] / cy);
452 result.
x = (float) ((
elem[0][0] * v.
x) + (
elem[0][1] * v.
y) + (
elem[0][2] * v.
z));
453 result.
y = (float) ((
elem[1][0] * v.
x) + (
elem[1][1] * v.
y) + (
elem[1][2] * v.
z));
454 result.
z = (float) ((
elem[2][0] * v.
x) + (
elem[2][1] * v.
y) + (
elem[2][2] * v.
z));
469 if (i==0) i1=1;
else if (i==2) i2=1;
470 if (j==0) j1=1;
else if (j==2) j2=1;
488 for (i = 0; i < 3; i++)
489 for (j = 0; j < 3; j++)
492 double det =
elem[0][0] * f[0][0] +
493 elem[0][1] * f[1][0] +
494 elem[0][2] * f[2][0];
499 for (i = 0; i < 3; i++)
500 for (j = 0; j < 3; j++)
501 elem[i][j] = f[i][j] * inv;
551 return (a.
x * b.
x) + (a.
y * b.
y) + (a.
z * b.
z);
559 out.
x = (a.
y * b.
z) - (a.
z * b.
y);
560 out.
y = (a.
z * b.
x) - (a.
x * b.
z);
561 out.
z = (a.
x * b.
y) - (a.
y * b.
x);
567 void MConcat(
double in1[3][3],
double in2[3][3],
double out[3][3])
571 for (i=0 ; i<3 ; i++) {
572 for (j=0 ; j<3 ; j++) {
573 out[i][j] = in1[i][0] * in2[0][j] +
574 in1[i][1] * in2[1][j] +
575 in1[i][2] * in2[2][j];
620 #define DONT_INTERSECT 0
621 #define DO_INTERSECT 1
626 return ((a>=0 && b>=0) || (a<0 && b<0));
631 double x1,
double y1,
double x2,
double y2,
632 double x3,
double y3,
double x4,
double y4,
633 double& ix,
double& iy)
635 double a1, a2, b1, b2, c1, c2;
636 double r1, r2, r3, r4;
637 double denom, offset, num;
644 c1 = x2 * y1 - x1 * y2;
648 r3 = a1 * x3 + b1 * y3 + c1;
649 r4 = a1 * x4 + b1 * y4 + c1;
663 c2 = x4 * y3 - x3 * y4;
667 r1 = a2 * x1 + b2 * y1 + c2;
668 r2 = a2 * x2 + b2 * y2 + c2;
681 denom = a1 * b2 - a2 * b1;
684 offset = denom < 0 ? - denom / 2 : denom / 2;
690 num = b1 * c2 - b2 * c1;
691 ix = ( num < 0 ? num - offset : num + offset ) / denom;
693 num = a2 * c1 - a1 * c2;
694 iy = ( num < 0 ? num - offset : num + offset ) / denom;