OGS
Point3d.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "Point3d.h"
5
6namespace MathLib
7{
8Point3d::Point3d() : x_({0, 0, 0}) {}
9
10Point3d::Point3d(std::array<double, 3> x) : x_(x[0], x[1], x[2]) {}
11
12MathLib::Point3d operator*(Eigen::Matrix3d const& mat,
13 MathLib::Point3d const& p)
14{
15 auto const& result = (mat * p.asEigenVector3d()).eval();
16 return MathLib::Point3d{{result[0], result[1], result[2]}};
17}
18
19double sqrDist(MathLib::Point3d const& p0, MathLib::Point3d const& p1)
20{
21 return (p0.asEigenVector3d() - p1.asEigenVector3d()).squaredNorm();
22}
23
24bool lessEq(Point3d const& a, Point3d const& b, double eps)
25{
26 auto absAndRelDiffLargerThanEps = [eps](double const u,
27 double const v) -> bool
28 {
29 return std::abs(u - v) > eps * std::min(std::abs(v), std::abs(u)) &&
30 std::abs(u - v) > eps;
31 };
32
33 return std::lexicographical_compare(
34 a.data(), a.data() + 3, b.data(), b.data() + 3,
35 [&absAndRelDiffLargerThanEps](auto const u, auto const v)
36 {
37 if (absAndRelDiffLargerThanEps(u, v))
38 {
39 return u <= v;
40 }
41 return true;
42 });
43}
44
45extern const Point3d ORIGIN{{{0.0, 0.0, 0.0}}};
46} // namespace MathLib
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:55
const double * data() const
Definition Point3d.h:51
Eigen::Vector3d x_
Definition Point3d.h:59
MathLib::Point3d operator*(Eigen::Matrix3d const &mat, MathLib::Point3d const &p)
Definition Point3d.cpp:12
static const double p
static const double u
static const double v
bool lessEq(Point3d const &a, Point3d const &b, double eps)
Definition Point3d.cpp:24
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19
const Point3d ORIGIN
Definition Point3d.h:89