KrisLibrary  1.0.0
LinearPath.h
1 #ifndef MATH_LINEAR_PATH_H
2 #define MATH_LINEAR_PATH_H
3 
4 #include "function.h"
5 #include "vector.h"
6 #include "Interval.h"
7 #include <vector>
8 
9 namespace Math {
10 
12 {
13 public:
14  //if t is -Inf or +Inf, y specifies slope before/after function
15  struct ControlPoint {
16  Real t;
17  Real y;
18  };
19 
20  virtual void PreEval(Real t);
21  virtual Real Eval(Real t);
22  virtual Real Deriv(Real t);
23 
24  inline Real operator[](int i) const { return points[i].y; }
25  inline Real& operator[](int i) { return points[i].y; }
26  inline size_t size() const { return points.size(); }
27  std::vector<ControlPoint>::iterator GetSegment(Real t);
28  ClosedInterval Domain() const;
29  ClosedInterval Range() const;
30  bool IsValid() const;
31  void ScaleTime(Real s);
32  void OffsetTime(Real off);
33  void Concat(const PiecewiseLinearFunction& p); //adds p onto the end of this
34  void Append(const Real y,Real dt=Zero);
35 
36  bool Read(File& f);
37  bool Write(File& f) const;
38 
39  std::vector<ControlPoint> points;
40 };
41 
43 {
44 public:
45  struct ControlPoint {
46  Real t;
47  Vector x;
48  };
49 
50  virtual void PreEval(Real t);
51  virtual void Eval(Real t,Vector& x);
52  virtual void Deriv(Real t,Vector& dx);
53 
54  //overridable functions
55  //Interpolate x from a->b
56  //Set to be the difference x=a-b
57  virtual void Interpolate(const Vector& a,const Vector& b,Real u,Vector& x) const;
58  virtual void Difference(const Vector& a,const Vector& b,Vector& x) const;
59  virtual Real Distance(const Vector& a,const Vector& b) const;
60 
61  inline const Vector& operator[](int i) const { return points[i].x; }
62  inline Vector& operator[](int i) { return points[i].x; }
63  inline size_t size() const { return points.size(); }
64  std::vector<ControlPoint>::iterator GetSegment(Real t);
65  inline Real BeginTime() const { return points.front().t; }
66  inline Real EndTime() const { return points.back().t; }
67  bool IsValid() const;
68  Real Length() const;
69  void ArcLengthParameterize();
70  void ScaleTime(Real s);
71  void OffsetTime(Real off);
72  void Concat(const PiecewiseLinearPath& p); //adds p onto the end of this
73  void Append(const Vector& x,Real dt=Zero);
74 
75  bool Read(File& f);
76  bool Write(File& f) const;
77 
78  std::vector<ControlPoint> points;
79 };
80 
81 } //namespace Math
82 
83 #endif
Abstract base classes for function interfaces.
A closed interval [a,b].
Definition: Interval.h:49
Contains all definitions in the Math package.
Definition: WorkspaceBound.h:12
Definition: LinearPath.h:11
Definition: LinearPath.h:45
Definition: LinearPath.h:42
A cross-platform class for reading/writing binary data.
Definition: File.h:47
A function from R to R^n, identical to RealFunction except a vector is returned.
Definition: function.h:69