cheshirekow  v0.1.0
axis_angle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of fiber.
5  *
6  * fiber is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * fiber is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with fiber. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef FIBER_AXIS_ANGLE_H_
26 #define FIBER_AXIS_ANGLE_H_
27 
28 namespace fiber {
29 
32 template <typename Scalar>
33 class AxisAngle {
34  public:
36 
37  AxisAngle() : axis_(1, 0, 0), angle_(0) {}
38 
39  template <typename Derived>
40  AxisAngle(const _RValue<Scalar, Derived>& axis, Scalar angle)
41  : axis_(axis), angle_(angle) {}
42 
45  }
46 
47  const AxisType& GetAxis() const {
48  return axis_;
49  }
50 
51  template <class Exp>
52  void SetAxis(const _RValue<Scalar, Exp>& axis) {
53  static_assert(Exp::SIZE_ == 3,
54  "Cannot set an axis from a vector with size other than 3");
55  LValue(axis_) = axis;
56  }
57 
58  Scalar GetAngle() const {
59  return angle_;
60  }
61 
62  void SetAngle(const Scalar angle) {
63  angle_ = angle;
64  }
65 
66  private:
68  Scalar angle_;
69 };
70 
72 template <typename Scalar, int Axis>
74  : public _RValue<Scalar, CoordinateAxis<Scalar, Axis> > {
75  public:
76  enum {
77  SIZE_ = 3,
78  ROWS_ = 3,
79  COLS_ = 1
80  };
81 
82  Size size() const { return 3; }
83  Size rows() const { return 3; }
84  Size cols() const { return 1; }
85 
87  static_assert(0 <= Axis && Axis < 3,
88  "A primitive axis must have axis 0, 1, or 2");
89  }
90 
91  Scalar operator[](Index i) const {
92  return (i == Axis) ? Scalar(1.0) : Scalar(0.0);
93  }
94 
95  Scalar operator()(Index i, Index j) const {
96  assert(j == 0);
97  return (i == Axis) ? Scalar(1.0) : Scalar(0.0);
98  }
99 };
100 
102 template <typename Scalar, int Axis>
104  public:
106  angle_(0) {
107  }
108 
109  CoordinateAxisAngle(Scalar angle) :
110  angle_(angle) {
111  }
112 
116  return q;
117  }
118 
121  }
122 
123  Scalar GetAngle() const {
124  return angle_;
125  }
126 
127  void SetAngle(Scalar angle) {
128  angle_ = angle;
129  }
130 
131  private:
132  Scalar angle_;
133 };
134 
137 
141 
145 
149 
153 
154 } // namespace fiber
155 
156 #endif // FIBER_AXISANGLE_H_
CoordinateAxis< float, 0 > AxisXf
Definition: axis_angle.h:142
A 3x1 normal vector with one unity element.
Definition: axis_angle.h:73
AxisType axis_
Definition: axis_angle.h:67
CoordinateAxis< double, 1 > AxisYd
Definition: axis_angle.h:139
CoordinateAxis< float, 1 > AxisYf
Definition: axis_angle.h:143
void QuaternionToAxisAngle(const Quaternion< Scalar > &q, fiber::_LValue< Scalar, Exp > *axis, Scalar *angle)
Size rows() const
Definition: axis_angle.h:83
expression template for rvalues
Definition: rvalue.h:33
const AxisType & GetAxis() const
Definition: axis_angle.h:47
Size cols() const
Definition: axis_angle.h:84
Size size() const
Definition: axis_angle.h:82
CoordinateAxis< Scalar, Axis > GetAxis() const
Definition: axis_angle.h:119
CoordinateAxis< float, 2 > AxisZf
Definition: axis_angle.h:144
unsigned int Size
Definition: fiber.h:32
AxisAngle(const Quaternion< Scalar > &q)
Definition: axis_angle.h:43
AxisAngle(const _RValue< Scalar, Derived > &axis, Scalar angle)
Definition: axis_angle.h:40
void SetAxis(const _RValue< Scalar, Exp > &axis)
Definition: axis_angle.h:52
Scalar GetAngle() const
Definition: axis_angle.h:58
void SetAngle(const Scalar angle)
Definition: axis_angle.h:62
Quaternion< Scalar > ToQuaternion() const
Definition: axis_angle.h:113
CoordinateAxisAngle< float, 0 > CoordinateAxisAngleXf
Definition: axis_angle.h:150
CoordinateAxisAngle< double, 0 > CoordinateAxisAngleXd
Definition: axis_angle.h:146
CoordinateAxisAngle< float, 2 > CoordinateAxisAngleZf
Definition: axis_angle.h:152
int Index
Definition: fiber.h:31
AxisAngle< float > AxisAnglef
Definition: axis_angle.h:136
void CoordinateAxisAngleToQuaternion(const CoordinateAxisAngle< Scalar, Axis > &axis_angle, Quaternion< Scalar > *q)
CoordinateAxis< double, 0 > AxisXd
Definition: axis_angle.h:138
Matrix< Scalar, 3, 1 > AxisType
Definition: axis_angle.h:35
CoordinateAxisAngle< float, 1 > CoordinateAxisAngleYf
Definition: axis_angle.h:151
CoordinateAxis< double, 2 > AxisZd
Definition: axis_angle.h:140
Scalar operator()(Index i, Index j) const
Definition: axis_angle.h:95
An axis angle rotation about a coordinate axis.
Definition: axis_angle.h:103
CoordinateAxisAngle(Scalar angle)
Definition: axis_angle.h:109
AxisAngle< double > AxisAngled
Definition: axis_angle.h:135
CoordinateAxisAngle< double, 2 > CoordinateAxisAngleZd
Definition: axis_angle.h:148
Encodes a rotation in 3-dimensions by an return RView<Scalar, Exp, rows, Exp::COLS>(static_cast<Exp c...
Definition: axis_angle.h:33
Scalar operator[](Index i) const
Definition: axis_angle.h:91
Scalar GetAngle() const
Definition: axis_angle.h:123
void SetAngle(Scalar angle)
Definition: axis_angle.h:127
_LValue< Scalar, Exp > & LValue(_LValue< Scalar, Exp > &exp)
Explicitly expose _LValue of an expressions, can be used to help the compiler disambiguate overloads...
Definition: lvalue.h:77
CoordinateAxisAngle< double, 1 > CoordinateAxisAngleYd
Definition: axis_angle.h:147