a

Dependencies:   mbed mbed-rtos

Committer:
alexpirciu
Date:
Thu Mar 28 07:44:42 2019 +0000
Revision:
1:ceee5a608e7c
assa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexpirciu 1:ceee5a608e7c 1
alexpirciu 1:ceee5a608e7c 2 namespace math{
alexpirciu 1:ceee5a608e7c 3
alexpirciu 1:ceee5a608e7c 4 /**
alexpirciu 1:ceee5a608e7c 5 * @brief Construct a new Bezier Curve< T>:: Bezier Curve object
alexpirciu 1:ceee5a608e7c 6 *
alexpirciu 1:ceee5a608e7c 7 */
alexpirciu 1:ceee5a608e7c 8 template<class T>
alexpirciu 1:ceee5a608e7c 9 BezierCurve<T>::BezierCurve(){
alexpirciu 1:ceee5a608e7c 10 }
alexpirciu 1:ceee5a608e7c 11
alexpirciu 1:ceee5a608e7c 12 /**
alexpirciu 1:ceee5a608e7c 13 * @brief Construct a new Bezier Curve< T>:: Bezier Curve object
alexpirciu 1:ceee5a608e7c 14 *
alexpirciu 1:ceee5a608e7c 15 * @param a point A
alexpirciu 1:ceee5a608e7c 16 * @param b point B
alexpirciu 1:ceee5a608e7c 17 * @param c point C
alexpirciu 1:ceee5a608e7c 18 * @param d point D
alexpirciu 1:ceee5a608e7c 19 */
alexpirciu 1:ceee5a608e7c 20 template<class T>
alexpirciu 1:ceee5a608e7c 21 BezierCurve<T>::BezierCurve(std::complex<T> a,std::complex<T> b,std::complex<T> c,std::complex<T> d){
alexpirciu 1:ceee5a608e7c 22 this->points[0]=a;
alexpirciu 1:ceee5a608e7c 23 this->points[1]=b;
alexpirciu 1:ceee5a608e7c 24 this->points[2]=c;
alexpirciu 1:ceee5a608e7c 25 this->points[3]=d;
alexpirciu 1:ceee5a608e7c 26
alexpirciu 1:ceee5a608e7c 27 this->bezierCurve=this->CP2PF();
alexpirciu 1:ceee5a608e7c 28 this->FOder_bezierCurve=this->bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 29 this->SOder_bezierCurve=this->FOder_bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 30 }
alexpirciu 1:ceee5a608e7c 31
alexpirciu 1:ceee5a608e7c 32 /**
alexpirciu 1:ceee5a608e7c 33 * @brief Construct a new Bezier Curve< T>:: Bezier Curve object
alexpirciu 1:ceee5a608e7c 34 *
alexpirciu 1:ceee5a608e7c 35 * @param points Array of points
alexpirciu 1:ceee5a608e7c 36 */
alexpirciu 1:ceee5a608e7c 37 template<class T>
alexpirciu 1:ceee5a608e7c 38 BezierCurve<T>::BezierCurve(std::complex<T> points[BEZIER_ORDER+1])
alexpirciu 1:ceee5a608e7c 39 {
alexpirciu 1:ceee5a608e7c 40 for(int32_t i=0;i<=BEZIER_ORDER;++i){
alexpirciu 1:ceee5a608e7c 41 this->points[i]=points[i];
alexpirciu 1:ceee5a608e7c 42 }
alexpirciu 1:ceee5a608e7c 43 this->bezierCurve=this->CP2PF();
alexpirciu 1:ceee5a608e7c 44 this->FOder_bezierCurve=this->bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 45 this->SOder_bezierCurve=this->FOder_bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 46 }
alexpirciu 1:ceee5a608e7c 47
alexpirciu 1:ceee5a608e7c 48 /**
alexpirciu 1:ceee5a608e7c 49 * @brief Destroy the Bezier Curve< T>:: Bezier Curve object
alexpirciu 1:ceee5a608e7c 50 *
alexpirciu 1:ceee5a608e7c 51 */
alexpirciu 1:ceee5a608e7c 52 template<class T>
alexpirciu 1:ceee5a608e7c 53 BezierCurve<T>::~BezierCurve()
alexpirciu 1:ceee5a608e7c 54 {
alexpirciu 1:ceee5a608e7c 55 //dtor
alexpirciu 1:ceee5a608e7c 56 }
alexpirciu 1:ceee5a608e7c 57
alexpirciu 1:ceee5a608e7c 58 /**
alexpirciu 1:ceee5a608e7c 59 * @brief This metohd create a new polynomial function based on the complex points.
alexpirciu 1:ceee5a608e7c 60 *
alexpirciu 1:ceee5a608e7c 61 * @return The result polynomial function represent the Bezier curve.
alexpirciu 1:ceee5a608e7c 62 */
alexpirciu 1:ceee5a608e7c 63 template<class T>
alexpirciu 1:ceee5a608e7c 64 math::PolynomialFunction<std::complex<float>,BEZIER_ORDER> BezierCurve<T>::CP2PF(){
alexpirciu 1:ceee5a608e7c 65 math::PolynomialFunction<std::complex<float>,BEZIER_ORDER> pf;
alexpirciu 1:ceee5a608e7c 66
alexpirciu 1:ceee5a608e7c 67 const std::complex<T> temp_cst_3(3,0);
alexpirciu 1:ceee5a608e7c 68 const std::complex<T> temp_cst_2(2,0);
alexpirciu 1:ceee5a608e7c 69
alexpirciu 1:ceee5a608e7c 70 std::complex<T> coef1=temp_cst_3*(this->points[1]-this->points[0]);
alexpirciu 1:ceee5a608e7c 71 std::complex<T> coef2=temp_cst_3*(this->points[0]-temp_cst_2*this->points[1]+this->points[2]);
alexpirciu 1:ceee5a608e7c 72 std::complex<T> coef3=temp_cst_3*(this->points[1]-this->points[2])+this->points[3]-this->points[0];
alexpirciu 1:ceee5a608e7c 73 pf.setCoefficientValue(0,this->points[0]);
alexpirciu 1:ceee5a608e7c 74 pf.setCoefficientValue(1,coef1);
alexpirciu 1:ceee5a608e7c 75 pf.setCoefficientValue(2,coef2);
alexpirciu 1:ceee5a608e7c 76 pf.setCoefficientValue(3,coef3);
alexpirciu 1:ceee5a608e7c 77 return pf;
alexpirciu 1:ceee5a608e7c 78 }
alexpirciu 1:ceee5a608e7c 79
alexpirciu 1:ceee5a608e7c 80 /**
alexpirciu 1:ceee5a608e7c 81 * @brief Get the point on the bezier curve.
alexpirciu 1:ceee5a608e7c 82 *
alexpirciu 1:ceee5a608e7c 83 * @param input_value The input value, it must belong to interval [0,1].
alexpirciu 1:ceee5a608e7c 84 * @return The point as complex number
alexpirciu 1:ceee5a608e7c 85 */
alexpirciu 1:ceee5a608e7c 86 template<class T>
alexpirciu 1:ceee5a608e7c 87 std::complex<T> BezierCurve<T>::getValue(float input_value){
alexpirciu 1:ceee5a608e7c 88 T input_value_T=static_cast<T>(input_value);
alexpirciu 1:ceee5a608e7c 89 return this->bezierCurve.calculateValue(input_value);
alexpirciu 1:ceee5a608e7c 90 }
alexpirciu 1:ceee5a608e7c 91
alexpirciu 1:ceee5a608e7c 92 template<class T>
alexpirciu 1:ceee5a608e7c 93 /**
alexpirciu 1:ceee5a608e7c 94 * @brief Get the value of the first order derivative of Bezier curve
alexpirciu 1:ceee5a608e7c 95 *
alexpirciu 1:ceee5a608e7c 96 * @param input_value The input value [0,1]
alexpirciu 1:ceee5a608e7c 97 * @return The point as a complex number.
alexpirciu 1:ceee5a608e7c 98 *
alexpirciu 1:ceee5a608e7c 99 */
alexpirciu 1:ceee5a608e7c 100 std::complex<T> BezierCurve<T>::get_FO_DerivateValue(float input_value){
alexpirciu 1:ceee5a608e7c 101 T input_value_T=static_cast<T>(input_value);
alexpirciu 1:ceee5a608e7c 102 return this->FOder_bezierCurve.calculateValue(input_value_T);
alexpirciu 1:ceee5a608e7c 103 }
alexpirciu 1:ceee5a608e7c 104
alexpirciu 1:ceee5a608e7c 105 /**
alexpirciu 1:ceee5a608e7c 106 * @brief Get the value of the second order derivative of Bezier Curve.
alexpirciu 1:ceee5a608e7c 107 *
alexpirciu 1:ceee5a608e7c 108 * @param input_value The input value of the function have to belong to interval [0,1]
alexpirciu 1:ceee5a608e7c 109 * @return The resulted value as a complex number.
alexpirciu 1:ceee5a608e7c 110 */
alexpirciu 1:ceee5a608e7c 111 template<class T>
alexpirciu 1:ceee5a608e7c 112 std::complex<T> BezierCurve<T>::get_SO_DerivateValue(float input_value){
alexpirciu 1:ceee5a608e7c 113 T input_value_T=static_cast<T>(input_value);
alexpirciu 1:ceee5a608e7c 114
alexpirciu 1:ceee5a608e7c 115 return this->SOder_bezierCurve.calculateValue(input_value_T);
alexpirciu 1:ceee5a608e7c 116 }
alexpirciu 1:ceee5a608e7c 117
alexpirciu 1:ceee5a608e7c 118 /**
alexpirciu 1:ceee5a608e7c 119 * @brief Get the polynomial function, which respresents the Bezier curve.
alexpirciu 1:ceee5a608e7c 120 *
alexpirciu 1:ceee5a608e7c 121 */
alexpirciu 1:ceee5a608e7c 122 template<class T>
alexpirciu 1:ceee5a608e7c 123 math::PolynomialFunction<std::complex<T>,BEZIER_ORDER> BezierCurve<T>::getBezierCurve(){
alexpirciu 1:ceee5a608e7c 124 return this->bezierCurve;
alexpirciu 1:ceee5a608e7c 125 }
alexpirciu 1:ceee5a608e7c 126
alexpirciu 1:ceee5a608e7c 127 /**
alexpirciu 1:ceee5a608e7c 128 * @brief Get resulted polynomial function of the first order derivative
alexpirciu 1:ceee5a608e7c 129 *
alexpirciu 1:ceee5a608e7c 130 * @return math::PolynomialFunction<std::complex<T>,BEZIER_ORDER-1>
alexpirciu 1:ceee5a608e7c 131 */
alexpirciu 1:ceee5a608e7c 132 template<class T>
alexpirciu 1:ceee5a608e7c 133 math::PolynomialFunction<std::complex<T>,BEZIER_ORDER-1> BezierCurve<T>::getFODerivate(){
alexpirciu 1:ceee5a608e7c 134 return this->FOder_bezierCurve;
alexpirciu 1:ceee5a608e7c 135 }
alexpirciu 1:ceee5a608e7c 136
alexpirciu 1:ceee5a608e7c 137 template<class T>
alexpirciu 1:ceee5a608e7c 138 /**
alexpirciu 1:ceee5a608e7c 139 * @brief Get resulted polynomial function of the second order derivative
alexpirciu 1:ceee5a608e7c 140 *
alexpirciu 1:ceee5a608e7c 141 * @return math::PolynomialFunction<std::complex<T>,BEZIER_ORDER-2>
alexpirciu 1:ceee5a608e7c 142 */
alexpirciu 1:ceee5a608e7c 143 math::PolynomialFunction<std::complex<T>,BEZIER_ORDER-2> BezierCurve<T>::getSODerivate(){
alexpirciu 1:ceee5a608e7c 144 return this->SOder_bezierCurve;
alexpirciu 1:ceee5a608e7c 145 }
alexpirciu 1:ceee5a608e7c 146
alexpirciu 1:ceee5a608e7c 147 template<class T>
alexpirciu 1:ceee5a608e7c 148 /**
alexpirciu 1:ceee5a608e7c 149 * @brief Set the points for creating a new Bezier curve
alexpirciu 1:ceee5a608e7c 150 *
alexpirciu 1:ceee5a608e7c 151 * @param a point A
alexpirciu 1:ceee5a608e7c 152 * @param b point B
alexpirciu 1:ceee5a608e7c 153 * @param c point C
alexpirciu 1:ceee5a608e7c 154 * @param d point D
alexpirciu 1:ceee5a608e7c 155 */
alexpirciu 1:ceee5a608e7c 156 void BezierCurve<T>::setBezierCurve(std::complex<T> a,std::complex<T> b,std::complex<T> c,std::complex<T> d){
alexpirciu 1:ceee5a608e7c 157 this->points[0]=a;
alexpirciu 1:ceee5a608e7c 158 this->points[1]=b;
alexpirciu 1:ceee5a608e7c 159 this->points[2]=c;
alexpirciu 1:ceee5a608e7c 160 this->points[3]=d;
alexpirciu 1:ceee5a608e7c 161
alexpirciu 1:ceee5a608e7c 162 this->bezierCurve=this->CP2PF();
alexpirciu 1:ceee5a608e7c 163 this->FOder_bezierCurve=this->bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 164 this->SOder_bezierCurve=this->FOder_bezierCurve.derivateFO();
alexpirciu 1:ceee5a608e7c 165 }
alexpirciu 1:ceee5a608e7c 166
alexpirciu 1:ceee5a608e7c 167 }; // namespace math