minsegdist.h
00001 #ifndef MINSEGDIST
00002 #define MINSEGDIST
00003
00004 #include <Biarc.h>
00005 #include <assert.h>
00006
00007
00008
00009
00010
00011 template<class Vector>
00012 int double_critical_test(const Vector &a0, const Vector &a1,
00013 const Vector &t0a,const Vector &t1a,
00014 const Vector &b0, const Vector &b1,
00015 const Vector &t0b,const Vector &t1b) {
00016 Vector w = (a0+a1-b0-b1);
00017 float denum = w.norm();
00018 float val0 = (a0-a1).norm(), val1 = (b0-b1).norm();
00019
00020
00021
00022
00023
00024
00025
00026
00027 if (denum<=(val0+val1)) return 1;
00028
00029 float sina = (val0+val1)/denum;
00030 w.normalize();
00031 if ((w.dot(t0a)<-sina) && (w.dot(t1a)<-sina)) return 0;
00032 if ((w.dot(t0a)>sina) && (w.dot(t1a)>sina)) return 0;
00033 if ((w.dot(t0b)<-sina) && (w.dot(t1b)<-sina)) return 0;
00034 if ((w.dot(t0b)>sina) && (w.dot(t1b)>sina)) return 0;
00035
00036 return 1;
00037 }
00038
00039 template<class Vector>
00040 int double_critical_test_v2(const Vector &a0,const Vector &a1,const Vector3 &a2,
00041 const Vector &b0,const Vector &b1,const Vector3 &b2) {
00042
00043
00044
00045
00046 Vector ta0 = a1-a0, ta2 = a2-a1;
00047 ta0.normalize(); ta2.normalize();
00048
00049 Vector tb0 = b1-b0, tb2 = b2-b1;
00050 tb0.normalize(); tb2.normalize();
00051
00052 return double_critical_test(a0,a2,
00053 ta0,ta2,
00054 b0,b2,
00055 tb0,tb2);
00056 }
00057
00058 #endif // MINSEGDIST