# minsegdist.h

```00001 #ifndef MINSEGDIST
00002 #define MINSEGDIST
00003
00004 #include <Biarc.h>
00005 #include <assert.h>
00006
00007 /*
00008   The double criticality test is a translation
00009   of Jana's Matlab code (listing in her Thesis)
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   // Jana's Thesis eq 7.23
00021   // !! prevents thicknesscomputation on curves with a
00022   //    small number of nodes !!
00023   // not sure wheter this check is necessary in practice !!
00024   // assert(denum > val0+val1);
00025
00026   // do balls intersect?
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   // XXX :
00043   // Possible optimization : since the Bezier triangles are
00044   // equilateral, only 2 of the 4 norms need to be calculated!
00045   // smthing like : invnorma = 1./(a1-a0).norm(); (a1-a0)*invnorma ...
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
```

Generated on Mon Feb 8 17:22:35 2010 for libbiarc by  1.5.6