00001
00002
00003 #if !defined(__geom_ParametrizedLine_h__)
00004 #define __geom_ParametrizedLine_h__
00005
00006
00007 #if defined(DEBUG_geom) && !defined(DEBUG_ParametrizedLine)
00008 #define DEBUG_ParametrizedLine
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 ParametrizedLine {
00026 private:
00027
00028
00029
00030
00031
00033 typedef SegmentMath<N,T> Segment;
00034
00035 public:
00036
00037
00038
00039
00040
00042 typedef T Number;
00044 typedef ads::FixedArray<N,Number> Point;
00046 typedef ads::FixedArray<1,Number> ParameterPoint;
00047
00048 private:
00049
00050
00051
00052
00053
00054
00055 Segment _segment;
00056
00057 Point _derivative;
00058
00059 public:
00060
00061
00063
00064
00066 ParametrizedLine()
00067 {}
00068
00070 ParametrizedLine(const Point& source, const Point& target) :
00071 _segment(source, target),
00072 _derivative(_segment.getLength() * _segment.getTangent()) {
00073 assert(isValid());
00074 }
00075
00077 void
00078 build(const Point& source, const Point& target) {
00079 _segment.make(source, target);
00080 _derivative = _segment.getLength() * _segment.getTangent();
00081 assert(isValid());
00082 }
00083
00085 ParametrizedLine(const ParametrizedLine& other) :
00086 _segment(other._segment),
00087 _derivative(other._derivative)
00088 {}
00089
00091 ParametrizedLine&
00092 operator=(const ParametrizedLine& other) {
00093 if (this != &other) {
00094 _segment = other._segment;
00095 _derivative = other._derivative;
00096 }
00097 return *this;
00098 }
00099
00101 ~ParametrizedLine()
00102 {}
00103
00105
00107
00108
00110 Point
00111 computePosition(const ParameterPoint& parameterPoint) const {
00112 return _segment.getSource() +
00113 (parameterPoint[0] * _segment.getLength()) * _segment.getTangent();
00114 }
00115
00117 const Point&
00118 computeDerivative(const ParameterPoint& parameterPoint) const {
00119 return _derivative;
00120 }
00121
00123
00125
00126
00128 bool
00129 operator==(const ParametrizedLine& other) {
00130 return _segment == other._segment && _derivative == other._derivative;
00131 }
00132
00133
00135 bool
00136 operator!=(const ParametrizedLine& other) {
00137 return ! operator==(other);
00138 }
00139
00141
00142
00143
00144 private:
00145
00146
00147 bool
00148 isValid() {
00149 return _segment.getLength() != 0;
00150 }
00151 };
00152
00153
00154 END_NAMESPACE_GEOM
00155
00156 #endif