~ubuntu-branches/ubuntu/vivid/meshlab/vivid

« back to all changes in this revision

Viewing changes to vcglib/vcg/space/intersection2.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-10-08 16:40:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091008164041-0c2ealqv8b8uc20c
Tags: 1.2.2-1
* New upstream version
* Do not build filter_isoparametrization because liblevmar dependency
  is not (yet) in Debian
* Fix compilation with gcc-4.4, thanks to Jonathan Liu for the patch
  (closes: #539544)
* rules: Add compiler variables to the qmake call (for testing with new
  GCC versions)
* io_3ds.pro: Make LIBS and INCLUDEPATH point to Debian version of lib3ds
* io_epoch.pro: Make LIBS point to Debian version of libbz2
* control:
  - Move Homepage URL to the source package section
  - Update to standards-version 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
template<class SCALAR_TYPE>
57
57
    inline bool Convex(const Point2<SCALAR_TYPE> & p0,const Point2<SCALAR_TYPE> & p1,const Point2<SCALAR_TYPE> & p2)
58
58
{
59
 
  const SCALAR_TYPE EPSILON= SCALAR_TYPE(1e-8);
60
 
  return (((p0-p1)^(p2-p1))<=EPSILON);
 
59
  const SCALAR_TYPE EPS= SCALAR_TYPE(1e-8);
 
60
  return (((p0-p1)^(p2-p1))<=EPS);
61
61
}
62
62
 
63
63
///return if exist the intersection point
67
67
                                                                 const vcg::Line2<SCALAR_TYPE> & l1,
68
68
                                                                 Point2<SCALAR_TYPE> &p)
69
69
{
70
 
        const SCALAR_TYPE EPSILON= SCALAR_TYPE(1e-8);
 
70
        const SCALAR_TYPE Eps= SCALAR_TYPE(1e-8);
71
71
        ///first line
72
72
        SCALAR_TYPE x1=l0.Origin().X();
73
73
        SCALAR_TYPE y1=l0.Origin().Y(); 
84
84
 
85
85
        ///denominator
86
86
        SCALAR_TYPE den=((x1-x2)*(y3-y4))-((y1-y2)*(x3-x4));
87
 
        if (fabs(den)<EPSILON)
 
87
        if (fabs(den)<Eps)
88
88
                return false;
89
89
 
90
90
        SCALAR_TYPE d0=(x1*y2)-(y1*x2);
165
165
                                                                           const vcg::Segment2<SCALAR_TYPE> &seg1,
166
166
                                                                           Point2<SCALAR_TYPE> &p_inters)
167
167
{
168
 
  ///test intersection of bbox
169
 
  vcg::Box2<SCALAR_TYPE> bb0,bb1;
170
 
  bb0.Add(seg0.P0());
171
 
  bb0.Add(seg0.P1());
172
 
  bb1.Add(seg1.P0());
173
 
  bb1.Add(seg1.P1());
174
 
  if (!bb0.Collide(bb1))
175
 
          return false;
176
 
  else
177
 
  {
178
 
        ///first compute intersection between lines
179
 
        vcg::Line2<SCALAR_TYPE> l0,l1;
180
 
 
181
 
        l0.SetOrigin(seg0.P0());
182
 
        vcg::Point2<SCALAR_TYPE> dir0=seg0.P1()-seg0.P0();
183
 
        dir0.Normalize();
184
 
        l0.SetDirection(dir0);
185
 
        l1.SetOrigin(seg1.P0());
186
 
        vcg::Point2<SCALAR_TYPE> dir1=seg1.P1()-seg1.P0();
187
 
        dir1.Normalize();
188
 
        l1.SetDirection(dir1);
189
 
        return ((LineSegmentIntersection<SCALAR_TYPE>(l0,seg1,p_inters))&&
190
 
                        (LineSegmentIntersection<SCALAR_TYPE>(l1,seg0,p_inters)));
191
 
  }
 
168
                vcg::Line2<SCALAR_TYPE> l0,l1;
 
169
 
 
170
                l0.SetOrigin(seg0.P0());
 
171
                vcg::Point2<SCALAR_TYPE> dir0=seg0.P1()-seg0.P0();
 
172
                dir0.Normalize();
 
173
                l0.SetDirection(dir0);
 
174
 
 
175
                l1.SetOrigin(seg1.P0());
 
176
                vcg::Point2<SCALAR_TYPE> dir1=seg1.P1()-seg1.P0();
 
177
                dir1.Normalize();
 
178
                l1.SetDirection(dir1);
 
179
                bool b=LineLineIntersection(l0,l1,p_inters);
 
180
                SCALAR_TYPE len0=seg0.Length();
 
181
                SCALAR_TYPE len1=seg1.Length();
 
182
                SCALAR_TYPE d0=(seg0.P0()-p_inters).Norm();
 
183
                SCALAR_TYPE d1=(seg1.P0()-p_inters).Norm();
 
184
 
 
185
                if ((d0>len0)||(d1>len1))
 
186
                        return false;
 
187
 
 
188
                vcg::Point2<SCALAR_TYPE> dir2=p_inters-seg0.P0();
 
189
                vcg::Point2<SCALAR_TYPE> dir3=p_inters-seg1.P0();
 
190
                if (((dir2*dir0)<0)||((dir3*dir1)<0))
 
191
                        return false;
 
192
 
 
193
                return true;
 
194
 
192
195
}
193
 
 
194
196
/// interseciton between point and triangle
195
197
template<class SCALAR_TYPE>
196
198
    inline bool IsInsideTrianglePoint( const Triangle2<SCALAR_TYPE> & t,const Point2<SCALAR_TYPE> & p)
215
217
}
216
218
 
217
219
//intersection between a circle and a line
218
 
template<class SCALAR_TYPE>
219
 
        inline bool CircleLineIntersection(const vcg::Line2<SCALAR_TYPE> & line,
220
 
                                                                           const vcg::Point2<SCALAR_TYPE> &center,
221
 
                                                                           const SCALAR_TYPE &radius,
222
 
                                                                           vcg::Point2<SCALAR_TYPE> &p0,
223
 
                                                                           vcg::Point2<SCALAR_TYPE> &p1)
 
220
template<class ScalarType>
 
221
        inline bool CircleLineIntersection(const vcg::Line2<ScalarType> & line,
 
222
                                                                           const vcg::Point2<ScalarType> &center,
 
223
                                                                           const ScalarType &radius,
 
224
                                                                           vcg::Point2<ScalarType> &p0,
 
225
                                                                           vcg::Point2<ScalarType> &p1)
224
226
        {
225
 
                typedef typename SCALAR_TYPE ScalarType;
226
 
 
227
227
                ///translate with origin on the center
228
228
                ScalarType x1,x2,y1,y2;
229
229
                x1=line.Origin().X()-center.X();