Geometry.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Rhys Mainwaring
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #include <cmath>
19 
20 #include <ignition/math/config.hh>
21 #include <ignition/math/Vector2.hh>
22 #include <ignition/math/Vector3.hh>
23 
25 
26 /* The version of ignition math in Ubuntu Xenial is 2.2.3 and lacks of
27  * some features added after that version in the 2.x series */
28 
29 /* There is a bug in versions for ign-math in Bionic that does not
30  * define properly IGNITION_MATH_MAJOR_VERSION. Some magic to check
31  * defined variables but empty and assume 3.0.x series */
32 #define DO_EXPAND(VAL) VAL ## 1
33 #define EXPAND(VAL) DO_EXPAND(VAL)
34 #if (EXPAND(IGNITION_MATH_MAJOR_VERSION) == 1)
35  #define MAJOR_VERSION 3
36  #define MINOR_VERSION 0
37 #else
38  #define MAJOR_VERSION IGNITION_MATH_MAJOR_VERSION
39  #define MINOR_VERSION IGNITION_MATH_MINOR_VERSION
40 #endif
41 
42 #if MAJOR_VERSION == 2 && MINOR_VERSION < 3
43  #define ign_math_vector2d_zero ignition::math::Vector2d(0, 0)
44  #define ign_math_vector3d_zero ignition::math::Vector3d(0, 0, 0)
45  #define _v_length sqrt(std::pow(_v[0], 2) + std::pow(_v[1], 2))
46  #define n_length sqrt(std::pow(n[0], 2) + std::pow(n[1], 2))
47 #else
48  #define ign_math_vector2d_zero ignition::math::Vector2d::Zero
49  #define ign_math_vector3d_zero ignition::math::Vector3d::Zero
50  #define _v_length _v.Length()
51  #define n_length n.Length()
52 #endif
53 
54 namespace asv
55 {
57  ignition::math::Vector2d
58  Geometry::Normalize(const ignition::math::Vector2d& _v)
59  {
60  if (_v == ign_math_vector2d_zero)
61  return _v;
62  else
63  return _v/_v_length;
64  }
65 
67  ignition::math::Vector3d
68  Geometry::Normalize(const ignition::math::Vector3d& _v)
69  {
70  if (_v == ign_math_vector3d_zero)
71  return _v;
72  else
73  return _v/_v_length;
74  }
75 
77  ignition::math::Vector3d Geometry::Normal(
78  const ignition::math::Vector3d& _p0,
79  const ignition::math::Vector3d& _p1,
80  const ignition::math::Vector3d& _p2
81  )
82  {
83  auto n = ignition::math::Vector3d::Normal(_p0, _p1, _p2);
84  if (n == ign_math_vector3d_zero)
85  return n;
86  else
87  return n/n_length;
88  }
89 }
static ignition::math::Vector3d Normal(const ignition::math::Vector3d &_v0, const ignition::math::Vector3d &_v1, const ignition::math::Vector3d &_v2)
Compute the (normalised) normal to the plane defined by a triangle.
Definition: Geometry.cc:77
static ignition::math::Vector2d Normalize(const ignition::math::Vector2d &_v)
Normalise a Vector2 (i.e. ensure it has unit length)
Definition: Geometry.cc:58
#define ign_math_vector2d_zero
Definition: Geometry.cc:48
This file contains methods to calculate properties of simple geometrical objects. ...
#define ign_math_vector3d_zero
Definition: Geometry.cc:49
#define _v_length
Definition: Geometry.cc:50
Definition: Geometry.hh:28
#define n_length
Definition: Geometry.cc:51


wave_gazebo_plugins
Author(s): Rhys Mainwaring
autogenerated on Thu May 7 2020 03:54:44