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


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:04:20