ad_map_access
PointOperation.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2018-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: MIT
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
12 #pragma once
13 
14 #include <cmath>
15 
18 #include "ad/physics/Distance.hpp"
19 #include "ad/physics/ParametricValue.hpp"
20 #include "ad/physics/RatioValue.hpp"
21 
23 namespace ad {
25 namespace map {
27 namespace point {
28 
37 template <typename PointType> PointType vectorCrossProduct(PointType const &a, PointType const &b)
38 {
39  PointType result;
40  result.x = a.y * b.z - a.z * b.y;
41  result.y = a.z * b.x - a.x * b.z;
42  result.z = a.x * b.y - a.y * b.x;
43  return result;
44 }
45 
54 template <typename PointType> double vectorDotProduct(PointType const &a, PointType const &b)
55 {
56  return static_cast<double>(a.x) * static_cast<double>(b.x) + static_cast<double>(a.y) * static_cast<double>(b.y)
57  + static_cast<double>(a.z) * static_cast<double>(b.z);
58 }
59 
65 template <typename PointType> PointType vectorMultiplyScalar(PointType const &a, double const &b)
66 {
67  PointType result;
68  result.x = a.x * b;
69  result.y = a.y * b;
70  result.z = a.z * b;
71  return result;
72 }
73 
79 template <typename PointType> PointType vectorMultiplyScalar(PointType const &a, physics::Distance const &b)
80 {
81  return vectorMultiplyScalar(a, static_cast<double>(b));
82 }
83 
91 template <typename PointType> physics::Distance vectorLength(PointType const &a)
92 {
93  physics::Distance const length(std::sqrt(static_cast<double>(vectorDotProduct(a, a))));
94  return length;
95 }
96 
104 template <typename PointType> PointType vectorNorm(PointType const &a)
105 {
106  physics::Distance const length = vectorLength(a);
107  if (length > physics::Distance(0.))
108  {
109  PointType result;
110  result.x = a.x / length;
111  result.y = a.y / length;
112  result.z = a.z / length;
113  return result;
114  }
115  return a;
116 }
117 
126 template <typename PointType> PointType vectorAdd(PointType const &a, PointType const &b)
127 {
128  PointType result;
129  result.x = a.x + b.x;
130  result.y = a.y + b.y;
131  result.z = a.z + b.z;
132  return result;
133 }
134 
143 template <typename PointType> PointType vectorSub(PointType const &a, PointType const &b)
144 {
145  PointType result;
146  result.x = a.x - b.x;
147  result.y = a.y - b.y;
148  result.z = a.z - b.z;
149  return result;
150 }
151 
163 template <typename PointType>
164 PointType vectorInterpolate(PointType const &a, PointType const &b, physics::ParametricValue const &tparam)
165 {
166  return vectorExtrapolate(a, b, static_cast<double>(tparam));
167 }
168 
180 template <typename PointType> PointType vectorExtrapolate(PointType const &a, PointType const &b, double const &scalar)
181 {
182  PointType result;
183  result.x = (1 - scalar) * a.x + scalar * b.x;
184  result.y = (1 - scalar) * a.y + scalar * b.y;
185  result.z = (1 - scalar) * a.z + scalar * b.z;
186  return result;
187 }
188 
189 } // namespace point
190 } // namespace map
191 } // namespace ad
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ECEFCoordinateOperation.hpp
ad::map::point::vectorDotProduct
double vectorDotProduct(PointType const &a, PointType const &b)
calculate the dot product of two vectors
Definition: PointOperation.hpp:54
ad::map::point::vectorAdd
PointType vectorAdd(PointType const &a, PointType const &b)
add two vectors
Definition: PointOperation.hpp:126
ad::map::point::vectorExtrapolate
GeoPoint vectorExtrapolate(GeoPoint const &a, GeoPoint const &b, double const &scalar)
specialization of vectorExtrapolate for GeoPoint
Definition: GeoOperation.hpp:165
ad::map::point::vectorSub
PointType vectorSub(PointType const &a, PointType const &b)
subtract two vectors from each right
Definition: PointOperation.hpp:143
ad::map::point::vectorInterpolate
PointType vectorInterpolate(PointType const &a, PointType const &b, physics::ParametricValue const &tparam)
Interpolates point between two points.
Definition: PointOperation.hpp:164
ad::map::point::vectorMultiplyScalar
PointType vectorMultiplyScalar(PointType const &a, double const &b)
multiplies a vector with a scalar
Definition: PointOperation.hpp:65
ENUCoordinateOperation.hpp
ad::map::point::vectorLength
physics::Distance vectorLength(PointType const &a)
calculate the length of a vector
Definition: PointOperation.hpp:91
ad::map::point::vectorCrossProduct
PointType vectorCrossProduct(PointType const &a, PointType const &b)
calculate the cross product of two vectors
Definition: PointOperation.hpp:37
ad::map::point::vectorNorm
PointType vectorNorm(PointType const &a)
normalizes a vector
Definition: PointOperation.hpp:104