JSim 2026.06.01-p(1)
Loading...
Searching...
No Matches
box.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
10namespace frcsim {
11
15class Box : public Shape {
16public:
21 explicit Box(const Vector3& halfExtents);
22
23 virtual ~Box() = default;
24
25 ShapeType GetType() const override;
26 double CalculateVolume() const override;
27 Vector3 CalculateLocalInertia(double mass) const override;
28
33 const Vector3& GetHalfExtents() const;
34
35private:
36 Vector3 m_halfExtents;
37};
38
39inline Box::Box(const Vector3& halfExtents) : m_halfExtents(halfExtents) {}
40
41inline ShapeType Box::GetType() const { return ShapeType::BOX; }
42
43inline double Box::CalculateVolume() const {
44 return 8.0 * m_halfExtents.x * m_halfExtents.y * m_halfExtents.z;
45}
46
47inline Vector3 Box::CalculateLocalInertia(double mass) const {
48 double lx2 = 4.0 * m_halfExtents.x * m_halfExtents.x;
49 double ly2 = 4.0 * m_halfExtents.y * m_halfExtents.y;
50 double lz2 = 4.0 * m_halfExtents.z * m_halfExtents.z;
51 double factor = mass / 12.0;
52 return Vector3(factor * (ly2 + lz2), factor * (lx2 + lz2), factor * (lx2 + ly2));
53}
54
55inline const Vector3& Box::GetHalfExtents() const { return m_halfExtents; }
56
57} // namespace frcsim
Box(const Vector3 &halfExtents)
Constructs a new Box centered at the local origin.
Definition box.hpp:39
virtual ~Box()=default
const Vector3 & GetHalfExtents() const
Gets the half extents of the box.
Definition box.hpp:55
double CalculateVolume() const override
Calculates the volume of the specific shape.
Definition box.hpp:43
ShapeType GetType() const override
Gets the exact type of this shape.
Definition box.hpp:41
Vector3 CalculateLocalInertia(double mass) const override
Computes the diagonal of the local inertia tensor for this shape given a mass.
Definition box.hpp:47
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
@ BOX
Definition shape.hpp:15
3D vector utility used throughout JSim physics.
Definition vector.hpp:22
double x
X component.
Definition vector.hpp:24