Point3.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 
17 #include <gtsam/geometry/Point3.h>
18 #include <cmath>
19 #include <iostream>
20 
21 using namespace std;
22 
23 namespace gtsam {
24 
25 /* ************************************************************************* */
26 double distance3(const Point3 &p1, const Point3 &q, OptionalJacobian<1, 3> H1,
28  double d = (q - p1).norm();
29  if (H1) {
30  *H1 << p1.x() - q.x(), p1.y() - q.y(), p1.z() - q.z();
31  *H1 = *H1 *(1. / d);
32  }
33  if (H2) {
34  *H2 << -p1.x() + q.x(), -p1.y() + q.y(), -p1.z() + q.z();
35  *H2 = *H2 *(1. / d);
36  }
37  return d;
38 }
39 
41  double r = sqrt(p.x() * p.x() + p.y() * p.y() + p.z() * p.z());
42  if (H) {
43  if (std::abs(r) > 1e-10)
44  *H << p.x() / r, p.y() / r, p.z() / r;
45  else
46  *H << 1, 1, 1; // really infinity, why 1 ?
47  }
48  return r;
49 }
50 
52  Point3 normalized = p / p.norm();
53  if (H) {
54  // 3*3 Derivative
55  double x2 = p.x() * p.x(), y2 = p.y() * p.y(), z2 = p.z() * p.z();
56  double xy = p.x() * p.y(), xz = p.x() * p.z(), yz = p.y() * p.z();
57  *H << y2 + z2, -xy, -xz, -xy, x2 + z2, -yz, -xz, -yz, x2 + y2;
58  *H /= pow(x2 + y2 + z2, 1.5);
59  }
60  return normalized;
61 }
62 
65  if (H1) *H1 << skewSymmetric(-q.x(), -q.y(), -q.z());
66  if (H2) *H2 << skewSymmetric(p.x(), p.y(), p.z());
67  return Point3(p.y() * q.z() - p.z() * q.y(), p.z() * q.x() - p.x() * q.z(),
68  p.x() * q.y() - p.y() * q.x());
69 }
70 
71 double dot(const Point3 &p, const Point3 &q, OptionalJacobian<1, 3> H1,
73  if (H1) *H1 << q.x(), q.y(), q.z();
74  if (H2) *H2 << p.x(), p.y(), p.z();
75  return p.x() * q.x() + p.y() * q.y() + p.z() * q.z();
76 }
77 
78 Point3Pair means(const std::vector<Point3Pair> &abPointPairs) {
79  const size_t n = abPointPairs.size();
80  if (n == 0) throw std::invalid_argument("Point3::mean input Point3Pair vector is empty");
81  Point3 aSum(0, 0, 0), bSum(0, 0, 0);
82  for (const Point3Pair &abPair : abPointPairs) {
83  aSum += abPair.first;
84  bSum += abPair.second;
85  }
86  const double f = 1.0 / n;
87  return {aSum * f, bSum * f};
88 }
89 
90 /* ************************************************************************* */
91 ostream &operator<<(ostream &os, const gtsam::Point3Pair &p) {
92  os << p.first << " <-> " << p.second;
93  return os;
94 }
95 
96 /* ************************************************************************* */
97 
98 } // namespace gtsam
Vector3f p1
int n
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: Half.h:150
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
Matrix< float, 2, 1 > xy
Definition: LLT_solve.cpp:7
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
Point2 z2
double distance3(const Point3 &p1, const Point3 &q, OptionalJacobian< 1, 3 > H1, OptionalJacobian< 1, 3 > H2)
distance between two points
Definition: Point3.cpp:26
Point3 cross(const Point3 &p, const Point3 &q, OptionalJacobian< 3, 3 > H1, OptionalJacobian< 3, 3 > H2)
cross product
Definition: Point3.cpp:63
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
EIGEN_DEVICE_FUNC const Scalar & q
double norm3(const Point3 &p, OptionalJacobian< 1, 3 > H)
Distance of the point from the origin, with Jacobian.
Definition: Point3.cpp:40
traits
Definition: chartTesting.h:28
Matrix3 skewSymmetric(double wx, double wy, double wz)
Definition: base/Matrix.h:404
Point3 normalize(const Point3 &p, OptionalJacobian< 3, 3 > H)
normalize, with optional Jacobian
Definition: Point3.cpp:51
ofstream os("timeSchurFactors.csv")
ostream & operator<<(ostream &os, const gtsam::Point3Pair &p)
Definition: Point3.cpp:91
3D Point
Point3Pair means(const std::vector< Point3Pair > &abPointPairs)
Calculate the two means of a set of Point3 pairs.
Definition: Point3.cpp:78
float * p
Vector3 Point3
Definition: Point3.h:35
double dot(const Point3 &p, const Point3 &q, OptionalJacobian< 1, 3 > H1, OptionalJacobian< 1, 3 > H2)
dot product
Definition: Point3.cpp:71
Jet< T, N > pow(const Jet< T, N > &f, double g)
Definition: jet.h:570
#define abs(x)
Definition: datatypes.h:17
std::pair< Point3, Point3 > Point3Pair
Definition: Point3.h:38


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