29 if (sdf->HasElement(
"box"))
31 auto boxElem = sdf->GetElement(
"box");
32 if (boxElem->HasElement(
"size"))
34 ignition::math::Vector3d dim = boxElem->GetElement(
"size")
35 ->Get<ignition::math::Vector3d>();
36 if (dim[0] > epsilon && dim[1] > epsilon && dim[2] > epsilon)
51 else if (sdf->HasElement(
"sphere"))
53 auto sphereElem = sdf->GetElement(
"sphere");
54 if (sphereElem->HasElement(
"radius"))
56 auto r = sphereElem->GetElement(
"radius")->Get<
double>();
71 else if (sdf->HasElement(
"cylinder"))
73 auto cylinderElem = sdf->GetElement(
"cylinder");
74 if (cylinderElem->HasElement(
"radius") &&
75 cylinderElem->HasElement(
"length"))
77 auto r = cylinderElem->GetElement(
"radius")->Get<
double>();
78 auto l = cylinderElem->GetElement(
"length")->Get<
double>();
79 if (r > epsilon || l > epsilon)
90 throw ParseException(
"cylinder",
"missing <radius> or <length> element");
96 "geometry",
"missing <box>, <cylinder> or <sphere> element");
99 return std::unique_ptr<ShapeVolume>(shape);
133 std::stringstream ss;
143 waterSurface.
offset = fluidLevel;
161 std::stringstream ss;
171 waterSurface.
offset = fluidLevel;
180 volume = 4./3. * M_PI * r * r *
r;
187 std::stringstream ss;
199 double h = fluidLevel - (pose.Pos().Z() -
r);
206 double intLimitLower = -
r;
207 double intLimitUpper = (-
r + h) >
r ?
r : (-
r + h);
210 output.volume = (pow(
r, 2) * (intLimitUpper - intLimitLower)
211 - (pow(intLimitUpper, 3)/3.0 - pow(intLimitLower, 3)/3.0)) * M_PI;
212 output.centroid.X() = pose.Pos().X();
213 output.centroid.Y() = pose.Pos().Y();
215 if (output.volume > 0) {
217 output.centroid.X() = pose.Pos().X();
218 output.centroid.Y() = pose.Pos().Y();
220 output.centroid.Z() = (pow(
r, 2) / 2.0 *
221 (pow(intLimitUpper, 2) - pow(intLimitLower, 2)) -
222 (pow(intLimitUpper, 4) - pow(intLimitLower, 4))/ 4.0)
223 * M_PI / output.volume;
225 output.centroid.Z() = pose.Pos().Z() + output.centroid.Z();
BoxVolume(double x, double y, double z)
Default constructor.
std::string Display() override
Display string for cylinder shape.
std::string Display() override
Display string for box shape.
virtual std::string Display()
Display string for shape object.
std::unique_ptr< ShapeVolume > ShapeVolumePtr
float offset
Offset w.r.t. normal.
Volume CalculateVolume(const ignition::math::Pose3d &pose, double fluidLevel) override
Calculates volume + centroid of submerged shape if the shape is out of water returns Volume{}...
Volume CalculateVolume(const ignition::math::Pose3d &pose, double fluidLevel) override
Calculates volume + centroid of submerged shape if the shape is out of water returns Volume{}...
double r
Radius of sphere.
Polyhedron polyhedron
Polyhedron defining a cylinder.
double r
Radius of cylinder.
Submerged volume calculation using polyhedron based on: Exact Buoyancy for Polyhedra by Eric Catto...
Polyhedron polyhedron
Polyhedron defining a box.
double volume
Full volume of object.
double h
Height of cylinder.
Parent shape object for volume objects.
SphereVolume(double r)
Default constructor.
double averageLength
Average length of object estimate used for drag torque calculation.
std::string Display() override
Display string for sphere shape.
static std::unique_ptr< ShapeVolume > makeShape(const sdf::ElementPtr sdf)
Factory method for shape. Parses a shape object from sdf data.
ShapeType type
Type of shape.
Represents output volume with centroid.
Custom exception for parsing errors.
Represents a plane as a normal and offset.
CylinderVolume(double r, double l)
Default constructor.
Volume CalculateVolume(const ignition::math::Pose3d &pose, double fluidLevel) override
Calculates volume + centroid of submerged shape if the shape is out of water returns Volume{}...
Volume SubmergedVolume(const ignition::math::Vector3d &x, const ignition::math::Quaterniond &q, Plane &plane)
Compute submerge volume and center of buoyancy of a polyhedron.