vtf-logo

ParametrizedPlane.h

00001 // -*- C++ -*-
00002 
00003 #if !defined(__geom_ParametrizedPlane_h__)
00004 #define __geom_ParametrizedPlane_h__
00005 
00006 // If we are debugging the whole geom namespace.
00007 #if defined(DEBUG_geom) && !defined(DEBUG_ParametrizedPlane)
00008 #define DEBUG_ParametrizedPlane
00009 #endif
00010 
00011 #include <iostream>
00012 #include <cassert>
00013 #include <cmath>
00014 
00015 #include "SegmentMath.h"
00016 
00017 BEGIN_NAMESPACE_GEOM
00018 
00020 
00024 template<int N, typename T = double>
00025 class ParametrizedPlane {
00026 public:
00027 
00028   //
00029   // Public types.
00030   //
00031 
00033   typedef T Number;
00035   typedef ads::FixedArray<N,Number> Point;
00037   typedef ads::FixedArray<2,Number> ParameterPoint;
00038 
00039 private:
00040 
00041   //
00042   // Member data
00043   //
00044 
00045   Point _origin, _axis0, _axis1;
00046 
00047 public:
00048 
00049   //--------------------------------------------------------------------------
00051 
00052 
00054   ParametrizedPlane()
00055   {}
00056 
00058   ParametrizedPlane(const Point& p0, const Point& p1, const Point& p2) : 
00059     _origin(p0),
00060     _axis0(p1 - p0),
00061     _axis1(p2 - p0) {
00062     assert(isValid());
00063   }
00064 
00066   void
00067   build(const Point& p0, const Point& p1, const Point& p2) {
00068     _origin = p0;
00069     _axis0 = p1 - p0;
00070     _axis1 = p2 - p0;
00071     assert(isValid());
00072   }
00073 
00075   ParametrizedPlane(const ParametrizedPlane& other) : 
00076     _origin(other._origin),
00077     _axis0(other._axis0),
00078     _axis1(other._axis1)
00079   {}
00080 
00082   ParametrizedPlane& 
00083   operator=(const ParametrizedPlane& other) {
00084     if (this != &other) {
00085       _origin = other._origin;
00086       _axis0 = other._axis0;
00087       _axis1 = other._axis1;
00088     }
00089     return *this;
00090   }
00091 
00093   ~ParametrizedPlane()
00094   {}
00095 
00097   //--------------------------------------------------------------------------
00099 
00100 
00102   Point 
00103   computePosition(const ParameterPoint& parameterPoint) const {
00104     return _origin + parameterPoint[0] * _axis0 + parameterPoint[1] * _axis1;
00105   }
00106 
00108   void
00109   computeDerivative(const ParameterPoint& parameterPoint,
00110                     Point* dxds, Point* dxdt) const {
00111     *dxds = _axis0;
00112     *dxdt = _axis1;
00113   }
00114 
00116   //--------------------------------------------------------------------------
00118 
00119 
00121   bool
00122   operator==(const ParametrizedPlane& other) {
00123     return _origin == other._origin && _axis0 == other._axis0 && 
00124       _axis1 == other._axis1;
00125   }
00126 
00127 
00129   bool
00130   operator!=(const ParametrizedPlane& other) {
00131     return ! operator==(other);
00132   }
00133 
00135 private:
00136   //--------------------------------------------------------------------------
00137   // Private member functions.
00138   
00139   // Check that the lengths are non-zero and that the axis are linearly 
00140   // independent.
00141   bool
00142   isValid() {
00143     const Number m0 = computeMagnitude(_axis0);
00144     const Number m1 = computeMagnitude(_axis1);
00145     // If either axis has zero length.
00146     if (m0 == 0 || m1 == 0) {
00147       return false;
00148     }
00149     // If the axes are linearly dependent.
00150     if (geom::computeMagnitude((_axis0 - (m0 / m1) * _axis1) / m0) < 
00151         std::sqrt(std::numeric_limits<Number>::epsilon())) {
00152       return false;
00153     }
00154     return true;
00155   }
00156 };
00157 
00158 
00159 END_NAMESPACE_GEOM
00160 
00161 #endif

Generated on Fri Aug 24 12:55:56 2007 for Computational Geometry Package by  doxygen 1.4.7