~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/Eigen2/Eigen/src/Geometry/Rotation2D.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This file is part of Eigen, a lightweight C++ template library
2
 
// for linear algebra. Eigen itself is part of the KDE project.
3
 
//
4
 
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
5
 
//
6
 
// Eigen is free software; you can redistribute it and/or
7
 
// modify it under the terms of the GNU Lesser General Public
8
 
// License as published by the Free Software Foundation; either
9
 
// version 3 of the License, or (at your option) any later version.
10
 
//
11
 
// Alternatively, you can redistribute it and/or
12
 
// modify it under the terms of the GNU General Public License as
13
 
// published by the Free Software Foundation; either version 2 of
14
 
// the License, or (at your option) any later version.
15
 
//
16
 
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
 
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
 
// GNU General Public License for more details.
20
 
//
21
 
// You should have received a copy of the GNU Lesser General Public
22
 
// License and a copy of the GNU General Public License along with
23
 
// Eigen. If not, see <http://www.gnu.org/licenses/>.
24
 
 
25
 
#ifndef EIGEN_ROTATION2D_H
26
 
#define EIGEN_ROTATION2D_H
27
 
 
28
 
/** \geometry_module \ingroup Geometry_Module
29
 
  *
30
 
  * \class Rotation2D
31
 
  *
32
 
  * \brief Represents a rotation/orientation in a 2 dimensional space.
33
 
  *
34
 
  * \param _Scalar the scalar type, i.e., the type of the coefficients
35
 
  *
36
 
  * This class is equivalent to a single scalar representing a counter clock wise rotation
37
 
  * as a single angle in radian. It provides some additional features such as the automatic
38
 
  * conversion from/to a 2x2 rotation matrix. Moreover this class aims to provide a similar
39
 
  * interface to Quaternion in order to facilitate the writing of generic algorithms
40
 
  * dealing with rotations.
41
 
  *
42
 
  * \sa class Quaternion, class Transform
43
 
  */
44
 
template<typename _Scalar> struct ei_traits<Rotation2D<_Scalar> >
45
 
{
46
 
  typedef _Scalar Scalar;
47
 
};
48
 
 
49
 
template<typename _Scalar>
50
 
class Rotation2D : public RotationBase<Rotation2D<_Scalar>,2>
51
 
{
52
 
  typedef RotationBase<Rotation2D<_Scalar>,2> Base;
53
 
 
54
 
public:
55
 
 
56
 
  using Base::operator*;
57
 
 
58
 
  enum { Dim = 2 };
59
 
  /** the scalar type of the coefficients */
60
 
  typedef _Scalar Scalar;
61
 
  typedef Matrix<Scalar,2,1> Vector2;
62
 
  typedef Matrix<Scalar,2,2> Matrix2;
63
 
 
64
 
protected:
65
 
 
66
 
  Scalar m_angle;
67
 
 
68
 
public:
69
 
 
70
 
  /** Construct a 2D counter clock wise rotation from the angle \a a in radian. */
71
 
  inline Rotation2D(Scalar a) : m_angle(a) {}
72
 
 
73
 
  /** \returns the rotation angle */
74
 
  inline Scalar angle() const { return m_angle; }
75
 
 
76
 
  /** \returns a read-write reference to the rotation angle */
77
 
  inline Scalar& angle() { return m_angle; }
78
 
 
79
 
  /** \returns the inverse rotation */
80
 
  inline Rotation2D inverse() const { return -m_angle; }
81
 
 
82
 
  /** Concatenates two rotations */
83
 
  inline Rotation2D operator*(const Rotation2D& other) const
84
 
  { return m_angle + other.m_angle; }
85
 
 
86
 
  /** Concatenates two rotations */
87
 
  inline Rotation2D& operator*=(const Rotation2D& other)
88
 
  { return m_angle += other.m_angle; return *this; }
89
 
 
90
 
  /** Applies the rotation to a 2D vector */
91
 
  Vector2 operator* (const Vector2& vec) const
92
 
  { return toRotationMatrix() * vec; }
93
 
 
94
 
  template<typename Derived>
95
 
  Rotation2D& fromRotationMatrix(const MatrixBase<Derived>& m);
96
 
  Matrix2 toRotationMatrix(void) const;
97
 
 
98
 
  /** \returns the spherical interpolation between \c *this and \a other using
99
 
    * parameter \a t. It is in fact equivalent to a linear interpolation.
100
 
    */
101
 
  inline Rotation2D slerp(Scalar t, const Rotation2D& other) const
102
 
  { return m_angle * (1-t) + other.angle() * t; }
103
 
 
104
 
  /** \returns \c *this with scalar type casted to \a NewScalarType
105
 
    *
106
 
    * Note that if \a NewScalarType is equal to the current scalar type of \c *this
107
 
    * then this function smartly returns a const reference to \c *this.
108
 
    */
109
 
  template<typename NewScalarType>
110
 
  inline typename ei_cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type cast() const
111
 
  { return typename ei_cast_return_type<Rotation2D,Rotation2D<NewScalarType> >::type(*this); }
112
 
 
113
 
  /** Copy constructor with scalar type conversion */
114
 
  template<typename OtherScalarType>
115
 
  inline explicit Rotation2D(const Rotation2D<OtherScalarType>& other)
116
 
  {
117
 
    m_angle = Scalar(other.angle());
118
 
  }
119
 
 
120
 
  /** \returns \c true if \c *this is approximately equal to \a other, within the precision
121
 
    * determined by \a prec.
122
 
    *
123
 
    * \sa MatrixBase::isApprox() */
124
 
  bool isApprox(const Rotation2D& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
125
 
  { return ei_isApprox(m_angle,other.m_angle, prec); }
126
 
};
127
 
 
128
 
/** \ingroup Geometry_Module
129
 
  * single precision 2D rotation type */
130
 
typedef Rotation2D<float> Rotation2Df;
131
 
/** \ingroup Geometry_Module
132
 
  * double precision 2D rotation type */
133
 
typedef Rotation2D<double> Rotation2Dd;
134
 
 
135
 
/** Set \c *this from a 2x2 rotation matrix \a mat.
136
 
  * In other words, this function extract the rotation angle
137
 
  * from the rotation matrix.
138
 
  */
139
 
template<typename Scalar>
140
 
template<typename Derived>
141
 
Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
142
 
{
143
 
  EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
144
 
  m_angle = ei_atan2(mat.coeff(1,0), mat.coeff(0,0));
145
 
  return *this;
146
 
}
147
 
 
148
 
/** Constructs and \returns an equivalent 2x2 rotation matrix.
149
 
  */
150
 
template<typename Scalar>
151
 
typename Rotation2D<Scalar>::Matrix2
152
 
Rotation2D<Scalar>::toRotationMatrix(void) const
153
 
{
154
 
  Scalar sinA = ei_sin(m_angle);
155
 
  Scalar cosA = ei_cos(m_angle);
156
 
  return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
157
 
}
158
 
 
159
 
#endif // EIGEN_ROTATION2D_H