ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
rotations.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 #include <adore/mad/alfunction.h>
17 // #include <adore/mad/intervalarithmetic.h>
18 #define _USE_MATH_DEFINES //
19 #include <math.h>
20 #include <algorithm>
21 
22 namespace adore
23 {
24  namespace mad
25  {
26  template<typename T, int N>
27  adoreMatrix<T, N, N> rotationMatrix(T angle)
28  {
29  adoreMatrix<T, N, N> M;
30  M = dlib::identity_matrix<T>(N);
31  M(0, 0) = (std::cos)(angle); M(0, 1) = -(std::sin)(angle);
32  M(1, 0) = (std::sin)(angle); M(1, 1) = (std::cos)(angle);
33  return M;
34  }
35 
39  template<typename T>
40  class RotationFunction : public ALFunction<T, adoreMatrix<T, 2, 2>>
41  {
42  private:
47  //template<typename T>
48  class RotationFunctionPD : public ALFunction<T, adoreMatrix<T, 2, 2>>
49  {
50  private:
52  public:
53  typedef T DT;
54  typedef adoreMatrix<T, 2, 2> CT;
55  virtual CT f(DT x) const override
56  {
57  adoreMatrix<T, 2, 2> R;
58  R = dlib::ones_matrix<T>(2, 2);
59  R(0, 0) = 0; R(0, 1) = -m_sub->f(x);
60  R(1, 0) = m_sub->f(x); R(1, 1) = 0;
61  return R;
62  }
63  virtual DT limitHi() const override
64  {
65  return m_sub->limitHi();
66  }
67  virtual DT limitLo() const override
68  {
69  return m_sub->limitLo();
70  }
71  virtual void setLimits(DT lo, DT hi)override
72  {
73  m_sub->setLimits(lo, hi);
74  }
76  {
77  return new RotationFunctionPD(m_sub->clone());
78  }
80  {
82  }
83  virtual void bound(const DT& xmin, const DT& xmax, CT& ymin, CT& ymax)override
84  {
85  interval<T> sub_bound;
86  m_sub->bound(xmin, xmax, sub_bound.lb, sub_bound.ub);
87  ymin(0, 0) = 0; ymin(0, 1) = (-sub_bound).lb;
88  ymin(1, 0) = sub_bound.lb; ymin(1, 1) = 0;
89  ymax(0, 0) = 0; ymax(0, 1) = (-sub_bound).ub;
90  ymax(1, 0) = sub_bound.ub; ymax(1, 1) = 0;
91  }
92 
95  {
96  delete m_sub;
97  }
98  };
99 
100  private:
101  public:
102  typedef T DT;
103  typedef adoreMatrix<T, 2, 2> CT;
104  virtual CT f(DT x) const override
105  {
106  adoreMatrix<T, 2, 2> R;
107  R = dlib::ones_matrix<T>(2, 2);
108  R(0, 0) = (std::cos)(m_sub->f(x)); R(0, 1) = -(std::sin)(m_sub->f(x));
109  R(1, 0) = (std::sin)(m_sub->f(x)); R(1, 1) = (std::cos)(m_sub->f(x));
110  return R;
111  }
112  virtual DT limitHi() const override
113  {
114  return m_sub->limitHi();
115  }
116  virtual DT limitLo() const override
117  {
118  return m_sub->limitLo();
119  }
120  virtual void setLimits(DT lo, DT hi)override
121  {
122  m_sub->setLimits(lo, hi);
123  }
125  {
126  return new RotationFunction<T>(m_sub->clone());
127  }
129  {
130  return funop::mmultiply<T,2,2,2>(clone(), new RotationFunctionPD(m_sub->create_derivative()));
131  }
132  virtual void bound(const DT& xmin, const DT& xmax, CT& ymin, CT& ymax)override
133  {
134  interval<T> angle_bound, cos_bound, sin_bound;
135  m_sub->bound(xmin, xmax, angle_bound.lb, angle_bound.ub);
136  cos_bound = adore::mad::cos(angle_bound);
137  sin_bound = adore::mad::sin(angle_bound);
138  ymin(0, 0) = cos_bound.lb; ymin(0, 1) = (-sin_bound).lb;
139  ymin(1, 0) = sin_bound.lb; ymin(1, 1) = cos_bound.lb;
140  ymax(0, 0) = cos_bound.ub; ymax(0, 1) = (-sin_bound).ub;
141  ymax(1, 0) = sin_bound.ub; ymax(1, 1) = cos_bound.ub;
142  }
143 
146  {
147  delete m_sub;
148  }
149  };
150 
151  namespace funop
152  {
156  template<typename T>
157  ALFunction<T, adoreMatrix<T, 2, 1>>* rotate(ALFunction<T, T>* angle, ALFunction<T, adoreMatrix<T, 2, 1>>* vector)
158  {
159  return funop::mmultiply<T, 2,2,1>(new RotationFunction<T>(angle), vector);
160  }
161  }
162  }
163 }
Definition: alfunction.h:74
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax)=0
virtual ALFunction< DT, CT > * clone()=0
virtual CT f(DT x) const =0
virtual DT limitHi() const =0
virtual DT limitLo() const =0
virtual ALFunction< DT, CT > * create_derivative()=0
virtual void setLimits(DT lo, DT hi)=0
virtual CT f(DT x) const override
Definition: rotations.h:55
virtual DT limitHi() const override
Definition: rotations.h:63
RotationFunctionPD(ALFunction< T, T > *sub)
Definition: rotations.h:93
virtual DT limitLo() const override
Definition: rotations.h:67
virtual void setLimits(DT lo, DT hi) override
Definition: rotations.h:71
virtual ALFunction< T, adoreMatrix< T, 2, 2 > > * clone() override
Definition: rotations.h:75
virtual ~RotationFunctionPD()
Definition: rotations.h:94
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax) override
Definition: rotations.h:83
ALFunction< T, T > * m_sub
Definition: rotations.h:51
adoreMatrix< T, 2, 2 > CT
Definition: rotations.h:54
virtual ALFunction< DT, CT > * create_derivative() override
Definition: rotations.h:79
Definition: rotations.h:41
virtual void bound(const DT &xmin, const DT &xmax, CT &ymin, CT &ymax) override
Definition: rotations.h:132
virtual CT f(DT x) const override
Definition: rotations.h:104
adoreMatrix< T, 2, 2 > CT
Definition: rotations.h:103
RotationFunction(ALFunction< T, T > *sub)
Definition: rotations.h:144
virtual ALFunction< DT, CT > * create_derivative() override
Definition: rotations.h:128
virtual void setLimits(DT lo, DT hi) override
Definition: rotations.h:120
virtual DT limitLo() const override
Definition: rotations.h:116
virtual DT limitHi() const override
Definition: rotations.h:112
ALFunction< T, T > * m_sub
Definition: rotations.h:43
virtual ALFunction< T, adoreMatrix< T, 2, 2 > > * clone() override
Definition: rotations.h:124
T DT
Definition: rotations.h:102
virtual ~RotationFunction()
Definition: rotations.h:145
ALFunction< T, adoreMatrix< T, 2, 1 > > * rotate(ALFunction< T, T > *angle, ALFunction< T, adoreMatrix< T, 2, 1 >> *vector)
Definition: rotations.h:157
interval< T > cos(interval< T > x)
Definition: intervalarithmetic.h:225
interval< T > sin(interval< T > x)
Definition: intervalarithmetic.h:204
adoreMatrix< T, N, N > rotationMatrix(T angle)
Definition: rotations.h:27
x
Definition: adore_set_goal.py:30
Definition: areaofeffectconverter.h:20
Definition: intervalarithmetic.h:30
T ub
Definition: intervalarithmetic.h:31
T lb
Definition: intervalarithmetic.h:31