File: Ellipsoid.hh

package info (click to toggle)
ignition-math 6.10.0%2Bds3-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,252 kB
  • sloc: cpp: 28,553; python: 7,309; ansic: 1,463; ruby: 910; sh: 63; makefile: 18
file content (134 lines) | stat: -rw-r--r-- 5,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (C) 2020 Open Source Robotics Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
*/
#ifndef IGNITION_MATH_ELLIPSOID_HH_
#define IGNITION_MATH_ELLIPSOID_HH_

#include <optional>
#include "ignition/math/MassMatrix3.hh"
#include "ignition/math/Material.hh"

namespace ignition
{
  namespace math
  {
    // Inline bracket to help doxygen filtering.
    inline namespace IGNITION_MATH_VERSION_NAMESPACE {
    //
    /// \class Ellipsoid Ellipsoid.hh ignition/math/Ellipsoid.hh
    /// \brief A representation of a general ellipsoid.
    ///
    /// The ellipsoid class supports defining a ellipsoid with three radii and
    /// material properties. Radii are in meters. See Material for more on
    /// material properties.
    /// \tparam Precision Scalar numeric type.
    template<typename Precision>
    class Ellipsoid
    {
      /// \brief Default constructor. The default radius and length are both
      /// zero.
      public: Ellipsoid() = default;

      /// \brief Construct a ellipsoid with a Vector3 of three radii.
      /// \param[in] _radii The three radii (x, y, z) defining this ellipsoid
      public: explicit Ellipsoid(const Vector3<Precision> &_radii);

      /// \brief Construct a ellipsoid with three radii and a material.
      /// \param[in] _radii The three radii (x, y, z) defining this ellipsoid
      /// \param[in] _mat Material property for the ellipsoid.
      public: Ellipsoid(const Vector3<Precision> &_radii,
                  const Material &_mat);

      /// \brief Get the radius in meters.
      /// \return The radius of the ellipsoid in meters.
      public: Vector3<Precision> Radii() const;

      /// \brief Set the radius in meters.
      /// \param[in] _radii The radii of the ellipsoid in meters.
      public: void SetRadii(const Vector3<Precision> &_radii);

      /// \brief Get the material associated with this ellipsoid.
      /// \return The material assigned to this ellipsoid
      public: const Material &Mat() const;

      /// \brief Set the material associated with this ellipsoid.
      /// \param[in] _mat The material assigned to this ellipsoid
      public: void SetMat(const Material &_mat);

      /// \brief Get the mass matrix for this ellipsoid. This function
      /// is only meaningful if the ellipsoid's radii and material
      /// have been set.
      /// \return The computed mass matrix if parameters are valid
      /// (radius > 0), (length > 0), and (density > 0). Otherwise
      /// std::nullopt is returned.
      public: std::optional< MassMatrix3<Precision> > MassMatrix() const;

      /// \brief Check if this ellipsoid is equal to the provided ellipsoid.
      /// Radius, length, and material properties will be checked.
      public: bool operator==(const Ellipsoid &_ellipsoid) const;

      /// \brief Get the volume of the ellipsoid in m^3.
      /// \return Volume of the ellipsoid in m^3.
      public: Precision Volume() const;

      /// \brief Compute the ellipsoid's density given a mass value. The
      /// ellipsoid is assumed to be solid with uniform density. This
      /// function requires the ellipsoid's radius and length to be set to
      /// values greater than zero. The Material of the ellipsoid is ignored.
      /// \param[in] _mass Mass of the ellipsoid, in kg. This value should be
      /// greater than zero.
      /// \return Density of the ellipsoid in kg/m^3. A NaN is returned
      /// if radius, length or _mass is <= 0.
      public: Precision DensityFromMass(const Precision _mass) const;

      /// \brief Set the density of this ellipsoid based on a mass value.
      /// Density is computed using
      /// Precision DensityFromMass(const Precision _mass) const. The
      /// ellipsoid is assumed to be solid with uniform density. This
      /// function requires the ellipsoid's radius and length to be set to
      /// values greater than zero. The existing Material density value is
      /// overwritten only if the return value from this true.
      /// \param[in] _mass Mass of the ellipsoid, in kg. This value should be
      /// greater than zero.
      /// \return True if the density was set. False is returned if the
      /// ellipsoid's radius, length, or the _mass value are <= 0.
      /// \sa Precision DensityFromMass(const Precision _mass) const
      public: bool SetDensityFromMass(const Precision _mass);

      /// \brief Radius of the ellipsoid.
      private: Vector3<Precision> radii = Vector3<Precision>::Zero;

      /// \brief the ellipsoid's material.
      private: Material material;
    };

    /// \typedef Ellipsoid<int> Ellipsoidi
    /// \brief Ellipsoid with integer precision.
    typedef Ellipsoid<int> Ellipsoidi;

    /// \typedef Ellipsoid<double> Ellipsoidd
    /// \brief Ellipsoid with double precision.
    typedef Ellipsoid<double> Ellipsoidd;

    /// \typedef Ellipsoid<float> Ellipsoidf
    /// \brief Ellipsoid with float precision.
    typedef Ellipsoid<float> Ellipsoidf;
    }
  }
}
#include "ignition/math/detail/Ellipsoid.hh"

#endif