29 #pragma package(smart_init)
32 (
double *norm,
double *root,
double *pnt)
35 return Closest_Point_to_Plane_3d(norm,root,pnt,
res);
40 double pr[3], sn,sd,sb;
62 double u[3], v[3], w[3];
123 else if ((-d + b) >
a)
131 sc = (fabs(sN) <
SMALL_NUM ? 0.0 : sN / sD);
132 tc = (fabs(tN) <
SMALL_NUM ? 0.0 : tN / tD);
137 P1[i] = S11[i] + sc * u[i];
138 P2[i] = S21[i] + tc * v[i];
139 dP[i] = w[i] + (sc * u[i]) - (tc * v[i]);
156 (
double *norm,
double *root,
double *pnt)
158 double D = -(norm[0]*root[0]+norm[1]*root[1]+norm[2]*root[2]);
160 return (norm[0]*pnt[0]+norm[1]*pnt[1]+norm[2]*pnt[2]+D)/
sqrt(fabs(norm[0]*norm[0]+norm[1]*norm[1]+norm[2]*norm[2]));
249 for (
int i = 0; i < 2; i++)
250 v[i] = SP1[i] - SP0[i];
253 for (
int i = 0; i < 2; i++)
254 w[i] =
P[i] - SP0[i];
256 double c1 = v[0]*w[0]+v[1]*w[1];
257 double c2 = v[0]*v[0]+v[1]*v[1];
259 if (c2 < 1E-6*fabs(c1) || c2 == 0.0
f )
269 for (
int i = 0; i < 2; i++)
276 for (
int i = 0; i < 2; i++)
281 for (
int i = 0; i < 2; i++)
282 result[i] = SP0[i] + t[0] * v[i];
290 double closestPoint[2], tmpt;
299 (
double a[3],
double b[3],
double c[3])
301 double closestPoint[3];
303 Closest_Point_to_Segment_3d(
a,b,c,closestPoint);
305 return VEC3_DISTANCE_VEC3(closestPoint, c);
309 (
double *norm,
double *root,
double *pnt,
double *proj_pnt)
311 double d = Dist3D_Point_Plan
314 for (
int i=0; i<3; i++)
315 proj_pnt[i] = pnt[i] - d*norm[i];
321 (
double P0[3],
double P1[3],
double O[3],
double V[3],
double *p_coef,
double EPSILON)
330 for (i = 0; i < 3; i++) u[i] = P1[i] - P0[i];
331 for (i = 0; i < 3; i++) w[i] = P0[i] - O[i];
333 D =
V[0]*u[0]+
V[1]*u[1]+
V[2]*u[2];
334 N = -(
V[0]*w[0]+
V[1]*w[1]+
V[2]*w[2]);
338 if (fabs(D) < EPSILON) {
339 if (fabs(N) < EPSILON)
348 if ( coef+EPSILON < 0.0 || coef-EPSILON > 1.0)
367 (
double P0[3],
double P1[3],
double O[3],
double V[3],
double *p_coef,
double *distance,
double EPSILON)
369 double dist_P0 = Dist3D_Point_Plan
371 if ( fabs(dist_P0) < EPSILON )
374 double dist_P1 = Dist3D_Point_Plan
376 if ( fabs(dist_P1) < EPSILON )
379 double prodDist = dist_P0 * dist_P1;
384 VEC3_MINUS_VEC3(P1,P0,direction);
386 *p_coef = -dist_P0/(VEC3_DOT_VEC3(direction,
V));
396 VEC3_MINUS_VEC3(P1,P0,direction);
398 double dirDotNormal = VEC3_DOT_VEC3(direction,
V);
399 if (dirDotNormal > EPSILON)
400 *p_coef = -dist_P0/dirDotNormal;
403 *distance = (fabs(dist_P0) < fabs(dist_P1)) ? fabs(dist_P0) : fabs(dist_P1) ;
408 if ( dist_P0 != 0.0 || dist_P0 != 0.0 )
421 if ( dist_P0 == 0.0 && dist_P0 == 0.0 )
437 for (
int i=0;i<3;i++)
438 sn += - (planeNormal[i] - (
P[i] - planeRootPoint[i]));
442 for (
int i=0;i<3;i++)
443 sd += (planeNormal[i]*planeNormal[i]);
449 for (
int i=0;i<3;i++)
450 B[i] =
P[i] + sb * planeNormal[i];
453 return sqrt(pow(
P[0]-B[0],2)+pow(
P[1]-B[1],2)+pow(
P[2]-B[2],2));
458 (
double __v0[3],
double __v1[3],
double __v2[3])
460 double s01[3], s12[3];
461 VEC3_MINUS_VEC3(__v1, __v0, s01);
462 VEC3_MINUS_VEC3(__v2, __v1, s12);
464 double s01Dots12 = VEC3_DOT_VEC3(s01, s12);
465 double norm_s01 = VEC3_NORM(s01);
466 double norm_s12 = VEC3_NORM(s12);
468 if (norm_s01*norm_s12 < 1E-28)
471 double proj = s01Dots12/(norm_s01*norm_s12);
477 double angle =
acos (proj);
489 (
double p[3],
double theta,
double r[3],
double q[3])
491 double costheta,sintheta;
494 costheta =
cos(theta);
495 sintheta =
sin(theta);
497 q[0] = q[1] = q[2] = 0;
499 q[0] += (costheta + (1 - costheta) * r[0] * r[0]) * p[0];
500 q[0] += ((1 - costheta) * r[0] * r[1] - r[2] * sintheta) * p[1];
501 q[0] += ((1 - costheta) * r[0] * r[2] + r[1] * sintheta) * p[2];
503 q[1] += ((1 - costheta) * r[0] * r[1] + r[2] * sintheta) * p[0];
504 q[1] += (costheta + (1 - costheta) * r[1] * r[1]) * p[1];
505 q[1] += ((1 - costheta) * r[1] * r[2] - r[0] * sintheta) * p[2];
507 q[2] += ((1 - costheta) * r[0] * r[2] - r[1] * sintheta) * p[0];
508 q[2] += ((1 - costheta) * r[1] * r[2] + r[0] * sintheta) * p[1];
509 q[2] += (costheta + (1 - costheta) * r[2] * r[2]) * p[2];
512 #define SMALL_NUM 0.00000001 // anything that avoids division overflow
515 double u[2],v[2],w[2];
534 if (du==0 && dv==0) {
571 if (t0 > 1 || t1 < 0) {
577 for (
int i=0; i<2; i++)
578 __intrPoint[i] = S2P0[i] + t0 * v[i];
583 for (
int i=0; i<2; i++)
584 __intrPoint[i] = S2P0[i] + t0 * v[i];
586 for (
int i=0; i<2; i++)
587 __intrEndPointSeg[i] = S2P0[i] + t1 * v[i];
595 if (sI < 0 || sI > 1)
600 if (tI < 0 || tI > 1)
603 for (
int i=0; i<2; i++)
604 __intrPoint[i] = S1P0[i] + sI * u[i];
611 double u[3], v[3], n[3];
645 for (
int i=0; i<3; i++)
646 I[i] = RP0[i] + r*dir[i];
649 double uu, uv, vv, wu, wv, D;
653 for (
int i=0; i<3; i++)
654 w[i] = I[i] - TV0[i];
657 D = uv * uv - uu * vv;
661 s = (uv * wv - vv * wu) / D;
662 if (s < 0.0 || s > 1.0)
664 t = (uv * wu - uu * wv) / D;
665 if (t < 0.0 || (s + t) > 1.0)
677 double u[3], v[3], n[3];
678 double dir[3], RP0[3];
692 int signD = (D<0)?-1:+1;
695 for (
int i=0; i<3; i++)
697 for (
int i=0; i<3; i++)
698 RP0[i] = P0[i]-dir[i];
711 double u[3], v[3], n[3];
712 double dir[3], RP0[3];
724 for (
int i=0; i<3; i++)
725 dir[i] = SP1[i]-SP0[i];
740 double ITSP0, ISP0[3], ITSP1, ISP1[3];
756 double S01[3],S12[3];
757 for (
int i=0;i<3;i++)
758 S01[i]=TV1[i]-TV0[i];
759 for (
int i=0;i<3;i++)
760 S12[i]=TV2[i]-TV1[i];