Ravelin
Rot2.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef ROT2
8 #error This class is not to be included by the user directly. Use Rotd.h or Rotf.h instead.
9 #endif
10 
12 class ROT2
13 {
14  public:
15  ROT2() { theta = (REAL) 0.0; }
16  ROT2(REAL theta) { this->theta = theta; }
17  ROT2(const ROT2& q) { theta = q.theta; }
18  static ROT2 zero() { return ROT2((REAL) 0.0); }
19  static ROT2 identity() { return ROT2((REAL) 0.0); }
20  ROT2& set_identity() { theta = (REAL) 0.0; return *this; }
21  ROT2& set_zero() { theta = (REAL) 0.0; return *this; }
22  ROT2& invert() { theta = -theta; return *this; }
23  ROT2 inverse() const { return ROT2(-theta); }
24  static ROT2 invert(const ROT2& r) { return ROT2(-r.theta); }
25  ROT2& operator=(const ROT2& q) { theta = q.theta; return *this; }
26  ROT2 operator*(const ROT2& q) const { return ROT2(theta + q.theta); }
27  ROT2 operator/(const ROT2& q) const { return ROT2(theta - q.theta); }
28  ROT2 operator*(REAL scalar) const { return ROT2(theta * scalar); }
29  ROT2 operator/(REAL scalar) const { return operator*(1.0/scalar); }
30  ROT2& operator*=(const ROT2& q) { theta += q.theta; return *this; }
31  ROT2& operator*=(REAL scalar) { theta *= scalar; return *this; }
32  ROT2& operator/=(REAL scalar) { return operator*=(1.0/scalar); }
33 
34  ORIGIN2 operator*(const ORIGIN2& o) const
35  {
36  REAL cth = std::cos(theta);
37  REAL sth = std::sin(theta);
38  return ORIGIN2(cth*o.x() + sth*o.y(), -sth*o.x() + cth*o.y());
39  }
40 
41  VECTOR2 operator*(const VECTOR2& o) const
42  {
43  REAL cth = std::cos(theta);
44  REAL sth = std::sin(theta);
45  return VECTOR2(cth*o.x() + sth*o.y(), -sth*o.x() + cth*o.y());
46  }
47 
49  REAL theta;
50 };
51 
52 inline std::ostream& operator<<(std::ostream& out, const ROT2& q)
53 {
54  out << "2D rotation: " << q.theta << std::endl;
55  return out;
56 }
57 
REAL theta
angle of rotation
Definition: Rot2.h:49
A two-dimensional floating point vector used for computational geometry calculations and with associa...
Definition: Vector2.h:15
Represents an orientation in 2D.
Definition: Rot2.h:12
A two-dimensional floating point vector used for computational geometry calculations and without asso...
Definition: Origin2.h:14