JSim 2026.06.01-p(1)
Loading...
Searching...
No Matches
cylinder.hpp
Go to the documentation of this file.
1// Copyright (c) JSim contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the LGPLv3 license file in the root directory of this project.
4
5#pragma once
6
9#ifndef M_PI
10#define M_PI 3.14159265358979323846
11#endif
12#include <cmath>
13
14namespace frcsim {
15
19class Cylinder : public Shape {
20public:
26 Cylinder(double radius, double halfHeight);
27
28 virtual ~Cylinder() = default;
29
30 ShapeType GetType() const override;
31 double CalculateVolume() const override;
32 Vector3 CalculateLocalInertia(double mass) const override;
33
38 double GetRadius() const;
39
44 double GetHalfHeight() const;
45
46private:
47 double m_radius;
48 double m_halfHeight;
49};
50
51inline Cylinder::Cylinder(double radius, double halfHeight)
52 : m_radius(radius), m_halfHeight(halfHeight) {}
53
55
56inline double Cylinder::CalculateVolume() const {
57 return M_PI * m_radius * m_radius * 2.0 * m_halfHeight;
58}
59
60inline Vector3 Cylinder::CalculateLocalInertia(double mass) const {
61 double r2 = m_radius * m_radius;
62 double h2 = 4.0 * m_halfHeight * m_halfHeight;
63 double ixz = (1.0 / 12.0) * mass * (3.0 * r2 + h2);
64 double iy = 0.5 * mass * r2;
65 return Vector3(ixz, iy, ixz);
66}
67
68inline double Cylinder::GetRadius() const { return m_radius; }
69inline double Cylinder::GetHalfHeight() const { return m_halfHeight; }
70
71} // namespace frcsim
double GetHalfHeight() const
Gets the half-height of the cylinder.
Definition cylinder.hpp:69
Vector3 CalculateLocalInertia(double mass) const override
Computes the diagonal of the local inertia tensor for this shape given a mass.
Definition cylinder.hpp:60
virtual ~Cylinder()=default
double CalculateVolume() const override
Calculates the volume of the specific shape.
Definition cylinder.hpp:56
Cylinder(double radius, double halfHeight)
Constructs a new Cylinder.
Definition cylinder.hpp:51
double GetRadius() const
Gets the radius of the cylinder.
Definition cylinder.hpp:68
ShapeType GetType() const override
Gets the exact type of this shape.
Definition cylinder.hpp:54
Base class for all collision geometries in the physics engine.
Definition shape.hpp:28
Definition vector.hpp:13
ShapeType
Enum identifying the specific types of collision shapes available.
Definition shape.hpp:14
@ CYLINDER
Definition shape.hpp:17
#define M_PI
Definition sphere.hpp:9
3D vector utility used throughout JSim physics.
Definition vector.hpp:22