polyhedron_volume.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
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 #pragma once
19 
20 #include <cassert>
21 #include <vector>
22 #include <gazebo/common/common.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Quaternion.hh>
25 
26 namespace buoyancy
27 {
29  struct Plane
30  {
32  Plane();
33 
35  ignition::math::Vector3d normal;
36 
38  float offset;
39  };
40 
42  struct Volume
43  {
44  Volume();
45 
47  Volume& operator+=(const Volume& rhs);
48 
50  double volume;
51 
53  ignition::math::Vector3d centroid;
54  };
55 
58  class Polyhedron
59  {
61  public: struct Face
62  {
63  Face() = default;
64 
65  Face(int i1, int i2, int i3);
66 
68  int i1, i2, i3;
69  };
70 
76  public: static Polyhedron makeCube(double x,
77  double y,
78  double z);
79 
85  public: static Polyhedron makeCylinder(double r,
86  double l,
87  int n);
88 
91  public: Volume ComputeFullVolume();
92 
98  public: Volume SubmergedVolume(const ignition::math::Vector3d &x,
99  const ignition::math::Quaterniond &q,
100  Plane &plane);
101 
109  private: static Volume tetrahedronVolume(const ignition::math::Vector3d& v1,
110  const ignition::math::Vector3d& v2,
111  const ignition::math::Vector3d& v3,
112  const ignition::math::Vector3d& p =
113  ignition::math::Vector3d({0., 0., 0.}));
114 
123  private: static Volume clipTriangle(const ignition::math::Vector3d& v1,
124  const ignition::math::Vector3d& v2,
125  const ignition::math::Vector3d& v3,
126  double d1,
127  double d2,
128  double d3,
129  const ignition::math::Vector3d& p =
130  ignition::math::Vector3d({0., 0., 0.}));
131 
133  private: std::vector<ignition::math::Vector3d> vertices;
134 
136  private: std::vector<Face> faces;
137 
139  private: const double EPSILON = 1e-6;
140  }; // class Polyhedron
141 }
ignition::math::Vector3d normal
Vector3 normal to plane.
float offset
Offset w.r.t. normal.
std::vector< Face > faces
Object faces.
Polyhedron::Face Face
Plane()
Initializes plane at z=0.
Submerged volume calculation using polyhedron based on: Exact Buoyancy for Polyhedra by Eric Catto...
TFSIMD_FORCE_INLINE Vector3 & operator+=(const Vector3 &v)
Store vertex index for a triangular face.
ignition::math::Vector3d centroid
Vector3 representing volume centroid.
std::vector< ignition::math::Vector3d > vertices
Object vertices.
Represents output volume with centroid.
Represents a plane as a normal and offset.
double volume
Submerged volume of shape.


usv_gazebo_plugins
Author(s): Brian Bingham , Carlos Aguero
autogenerated on Thu May 7 2020 03:54:47