Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

point3.C

Go to the documentation of this file.
00001 /*!
00002  *  \file Point3.C
00003  *  \brief Contains the implementation of non-inline functions of the Point3 class
00004  *  and the Point3list class.
00005  *  \ingroup group_MLIB
00006  *
00007  */
00008 
00009 #include <climits>
00010 #include "mlib/point3.H"
00011 #include "mlib/vec3.H"
00012 #include "mlib/mat4.H"
00013 #include "mlib/plane.H"
00014 #include "mlib/line.H"
00015 
00016 template <typename P>
00017 MLIB_INLINE
00018 bool 
00019 mlib::areCoplanar(const P &p1, const P &p2, const P &p3, const P &p4)
00020 {
00021     return fabs(det(p2-p1,p3-p2,p4-p3)) < epsNorMath() * 
00022            (p2-p1).length_rect() * (p3-p2).length_rect() * (p4-p3).length_rect();
00023 }
00024 
00025 template <typename L, typename M, typename P, typename V, typename S>
00026 MLIB_INLINE
00027 void
00028 mlib::Point3list<L,M,P,V,S>::xform(const M &t)
00029 {
00030    for (int i=0; i<num(); i++)
00031       (*this)[i] = (t * (*this)[i]);
00032    update_length();
00033 }
00034 
00035 template <typename L, typename M, typename P, typename V, typename S>
00036 MLIB_INLINE
00037 bool
00038 mlib::Point3list<L,M,P,V,S>::fix_endpoints(P a, P b)
00039 {
00040    // Shift, rotate and scale the polyline so endpoints match a and b
00041 
00042    if (num() < 2) {
00043       err_msg("_point3d_list::fix_endpoints: too few points (%d)",
00044               num());
00045       return 0;
00046    }
00047 
00048    // Do nothing if we're already golden:
00049    if (a.is_equal((*this)[0]) && b.is_equal(last()))
00050       return 1;
00051 
00052    // Determine translation matrix to move 1st point to a:
00053    M xlate = M::translation(a - (*this)[0]);
00054 
00055    // Matrix to scale and rotate polyline (after the tranlation)
00056    // so last point agrees with b:
00057    M scale_rot = M::anchor_scale_rot(a, xlate*last(), b);
00058 
00059    // Don't proceed with a singular matrix:
00060    if (!scale_rot.is_valid()) {
00061       err_msg("_point3d_list::fix_endpoints: Error: singular matrix");
00062       return 0;
00063    }
00064 
00065    // Do it:
00066    xform(scale_rot * xlate);
00067 
00068    return 1;
00069 }
00070 
00071 template <typename L, typename M, typename P, typename V, typename S>
00072 MLIB_INLINE
00073 double
00074 mlib::Point3list<L,M,P,V,S>::winding_number(const P& o, const V& n) const
00075 {
00076 
00077    double ret=0;
00078    for (int i=1; i<num(); i++)
00079       ret += signed_angle((pt(i-1) - o).orthogonalized(n),
00080                           (pt(i  ) - o).orthogonalized(n),
00081                           n);
00082    return ret / TWO_PI;
00083 }
00084 
00085 /* end of file point3d.C */

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4