Ignition Math

API Reference

5.1.0
detail/Cylinder.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 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 #ifndef IGNITION_MATH_DETAIL_CYLINDER_HH_
18 #define IGNITION_MATH_DETAIL_CYLINDER_HH_
19 namespace ignition
20 {
21 namespace math
22 {
23 
25 template<typename T>
26 Cylinder<T>::Cylinder(const T _length, const T _radius,
27  const Quaternion<T> &_rotOffset)
28 {
29  this->length = _length;
30  this->radius = _radius;
31  this->rotOffset = _rotOffset;
32 }
33 
35 template<typename T>
36 Cylinder<T>::Cylinder(const T _length, const T _radius,
37  const Material &_mat, const Quaternion<T> &_rotOffset)
38 {
39  this->length = _length;
40  this->radius = _radius;
41  this->material = _mat;
42  this->rotOffset = _rotOffset;
43 }
44 
46 template<typename T>
48 {
49  return this->radius;
50 }
51 
53 template<typename T>
54 void Cylinder<T>::SetRadius(const T _radius)
55 {
56  this->radius = _radius;
57 }
58 
60 template<typename T>
62 {
63  return this->length;
64 }
65 
67 template<typename T>
68 void Cylinder<T>::SetLength(const T _length)
69 {
70  this->length = _length;
71 }
72 
74 template<typename T>
76 {
77  return this->rotOffset;
78 }
79 
81 template<typename T>
83 {
84  this->rotOffset = _rotOffset;
85 }
86 
88 template<typename T>
89 const Material &Cylinder<T>::Mat() const
90 {
91  return this->material;
92 }
93 
95 template<typename T>
96 void Cylinder<T>::SetMat(const Material &_mat)
97 {
98  this->material = _mat;
99 }
100 
102 template<typename T>
103 bool Cylinder<T>::operator==(const Cylinder &_cylinder) const
104 {
105  return equal(this->radius, _cylinder.Radius()) &&
106  equal(this->length, _cylinder.Length()) &&
107  this->material == _cylinder.Mat();
108 }
109 
111 template<typename T>
113 {
114  return _massMat.SetFromCylinderZ(
115  this->material, this->length,
116  this->radius, this->rotOffset);
117 }
118 
120 template<typename T>
122 {
123  return IGN_PI * std::pow(this->radius, 2) *
124  this->length;
125 }
126 
128 template<typename T>
130 {
131  T newDensity = this->DensityFromMass(_mass);
132  if (newDensity > 0)
133  this->material.SetDensity(newDensity);
134  return newDensity > 0;
135 }
136 
138 template<typename T>
139 T Cylinder<T>::DensityFromMass(const T _mass) const
140 {
141  if (this->radius <= 0 || this->length <=0 || _mass <= 0)
142  return -1.0;
143 
144  return _mass / this->Volume();
145 }
146 
147 }
148 }
149 #endif
Quaternion< Precision > RotationalOffset() const
Get the rotational offset. By default, a cylinder&#39;s length is aligned with the Z axis. The rotational offset encodes a rotation from the z axis.
Definition: detail/Cylinder.hh:75
bool operator==(const Cylinder &_cylinder) const
Check if this cylinder is equal to the provided cylinder. Radius, length, and material properties wil...
Definition: detail/Cylinder.hh:103
Cylinder()=default
Default constructor. The default radius and length are both zero. The default rotational offset is Qu...
void SetRadius(const Precision _radius)
Set the radius in meters.
Definition: detail/Cylinder.hh:54
void SetLength(const Precision _length)
Set the length in meters.
const Material & Mat() const
Get the material associated with this cylinder.
Definition: detail/Cylinder.hh:89
A class for inertial information about a rigid body consisting of the scalar mass and a 3x3 symmetric...
Definition: MassMatrix3.hh:45
bool MassMatrix(MassMatrix3d &_massMat) const
Get the mass matrix for this cylinder. This function is only meaningful if the cylinder&#39;s radius...
Definition: detail/Cylinder.hh:112
bool equal(const T &_a, const T &_b, const T &_epsilon=T(1e-6))
check if two values are equal, within a tolerance
Definition: Helpers.hh:552
Contains information about a single material.
Definition: Material.hh:65
void SetMat(const Material &_mat)
Set the material associated with this cylinder.
Definition: detail/Cylinder.hh:96
A represntation of a cylinder.
Definition: Cylinder.hh:43
Precision Volume() const
Get the volume of the cylinder in m^3.
Definition: detail/Cylinder.hh:121
Precision Length() const
Get the length in meters.
Definition: detail/Cylinder.hh:61
bool SetDensityFromMass(const Precision _mass)
Set the density of this cylinder based on a mass value. Density is computed using Precision DensityFr...
Definition: detail/Cylinder.hh:129
bool SetFromCylinderZ(const Material &_mat, const T _length, const T _radius, const Quaternion< T > &_rot=Quaternion< T >::Identity)
Set inertial properties based on a Material and equivalent cylinder aligned with Z axis...
Definition: MassMatrix3.hh:1118
void SetRotationalOffset(const Quaternion< Precision > &_rotOffset)
Set the rotation offset. See Quaternion<Precision> RotationalOffset() for details on the rotational o...
Definition: detail/Cylinder.hh:82
T pow(T... args)
Definition: Angle.hh:39
Precision Radius() const
Get the radius in meters.
Definition: detail/Cylinder.hh:47
A quaternion class.
Definition: Matrix3.hh:35
#define IGN_PI
Define IGN_PI, IGN_PI_2, and IGN_PI_4. This was put here for Windows support.
Definition: Helpers.hh:180
Precision DensityFromMass(const Precision _mass) const
Compute the cylinder&#39;s density given a mass value. The cylinder is assumed to be solid with uniform d...
Definition: detail/Cylinder.hh:139