Rot2.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #include <gtsam/geometry/Rot2.h>
20 #include <iostream>
21 
22 using namespace std;
23 
24 namespace gtsam {
25 
26 /* ************************************************************************* */
27 Rot2 Rot2::fromCosSin(double c, double s) {
28  if (std::abs(c * c + s * s - 1.0) > 1e-9) {
29  double norm_cs = sqrt(c*c + s*s);
30  c = c/norm_cs;
31  s = s/norm_cs;
32  }
33  return Rot2(c, s);
34 }
35 
36 /* ************************************************************************* */
37 Rot2 Rot2::atan2(double y, double x) {
38  Rot2 R(x, y);
39  return R.normalize();
40 }
41 
42 /* ************************************************************************* */
43 Rot2 Rot2::Random(std::mt19937& rng) {
44  uniform_real_distribution<double> randomAngle(-M_PI, M_PI);
45  double angle = randomAngle(rng);
46  return fromAngle(angle);
47 }
48 
49 /* ************************************************************************* */
50 void Rot2::print(const string& s) const {
51  cout << s << ": " << theta() << endl;
52 }
53 
54 /* ************************************************************************* */
55 bool Rot2::equals(const Rot2& R, double tol) const {
56  return std::abs(c_ - R.c_) <= tol && std::abs(s_ - R.s_) <= tol;
57 }
58 
59 /* ************************************************************************* */
61  double scale = c_*c_ + s_*s_;
62  if(std::abs(scale-1.0)>1e-10) {
63  scale = pow(scale, -0.5);
64  c_ *= scale;
65  s_ *= scale;
66  }
67  return *this;
68 }
69 
70 /* ************************************************************************* */
72  if (H)
73  *H = I_1x1;
74  if (v.isZero())
75  return (Rot2());
76  else
77  return Rot2::fromAngle(v(0));
78 }
79 
80 /* ************************************************************************* */
81 Vector1 Rot2::Logmap(const Rot2& r, OptionalJacobian<1, 1> H) {
82  if (H)
83  *H = I_1x1;
84  Vector1 v;
85  v << r.theta();
86  return v;
87 }
88 /* ************************************************************************* */
89 Matrix2 Rot2::matrix() const {
90  Matrix2 rvalue_;
91  rvalue_ << c_, -s_, s_, c_;
92  return rvalue_;
93 }
94 
95 /* ************************************************************************* */
96 Matrix2 Rot2::transpose() const {
97  Matrix2 rvalue_;
98  rvalue_ << c_, s_, -s_, c_;
99  return rvalue_;
100 }
101 
102 /* ************************************************************************* */
103 // see doc/math.lyx, SO(2) section
105  OptionalJacobian<2, 2> H2) const {
106  const Point2 q = Point2(c_ * p.x() + -s_ * p.y(), s_ * p.x() + c_ * p.y());
107  if (H1) *H1 << -q.y(), q.x();
108  if (H2) *H2 = matrix();
109  return q;
110 }
111 
112 /* ************************************************************************* */
113 // see doc/math.lyx, SO(2) section
116  const Point2 q = Point2(c_ * p.x() + s_ * p.y(), -s_ * p.x() + c_ * p.y());
117  if (H1) *H1 << q.y(), -q.x();
118  if (H2) *H2 = transpose();
119  return q;
120 }
121 
122 /* ************************************************************************* */
123 Rot2 Rot2::relativeBearing(const Point2& d, OptionalJacobian<1, 2> H) {
124  double x = d.x(), y = d.y(), d2 = x * x + y * y, n = sqrt(d2);
125  if(std::abs(n) > 1e-5) {
126  if (H) {
127  *H << -y / d2, x / d2;
128  }
129  return Rot2::fromCosSin(x / n, y / n);
130  } else {
131  if (H) *H << 0.0, 0.0;
132  return Rot2();
133  }
134 }
135 
136 /* ************************************************************************* */
137 
138 } // gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
Scalar * y
double s_
Definition: Rot2.h:38
Vector2 Point2
Definition: Point2.h:27
ArrayXcf v
Definition: Cwise_arg.cpp:1
static std::mt19937 rng
int n
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
#define M_PI
Definition: main.h:78
Rot2 R(Rot2::fromAngle(0.1))
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Pose2_ Expmap(const Vector3_ &xi)
Definition: Half.h:150
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Rot2 theta
static void normalize(Signature::Row &row)
Definition: Signature.cpp:158
double theta() const
Definition: Rot2.h:183
P unrotate(const T &r, const P &pt)
Definition: lieProxies.h:50
P rotate(const T &r, const P &pt)
Definition: lieProxies.h:47
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
EIGEN_DEVICE_FUNC const Scalar & q
Rot2 & normalize()
Definition: Rot2.cpp:60
Jet< T, N > atan2(const Jet< T, N > &g, const Jet< T, N > &f)
Definition: jet.h:556
traits
Definition: chartTesting.h:28
float * p
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
const G double tol
Definition: Group.h:83
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:570
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
The matrix class, also used for vectors and row-vectors.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
#define abs(x)
Definition: datatypes.h:17
double c_
Definition: Rot2.h:38
2D rotation


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:53