AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
Sphere.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGXCOLLIDE_SPHERE_H
18#define AGXCOLLIDE_SPHERE_H
19
20#include <agxCollide/Shape.h>
22
23
24namespace agxCollide
25{
26
32 {
33 public:
38 Sphere( agx::Real radius = agx::Real(0.5) );
39
40
44 void setRadius( agx::Real radius );
45
49 agx::Real getRadius() const;
50
51 /* Common shape methods */
52 virtual Shape *clone() const override;
53 virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
54 virtual agx::Real getVolume() const override;
55 virtual bool hasSupportFunction() const override;
56
61 virtual agx::Vec3 getSupportPoint(const agx::Vec3& supportDirection) const override;
62 virtual const BoundingAABB& updateBoundingVolume() override;
63 virtual BoundingAABB calculateLocalBound() const override;
64 virtual agx::Real calculateBoundingRadius( BoundingAABB& localAABB ) const override;
65
66 static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, agx::Real radius);
67
68 static agx::Real calculateVolume(agx::Real radius);
69
71
72
74 agx::Physics::Geometry::SpherePtr getEntity() const;
76
77 protected:
79 virtual ~Sphere( void );
80
81 };
82
83
84 /* Implementation */
85 AGX_FORCE_INLINE agx::Real Sphere::getRadius() const
86 {
87 return getEntity().radius();
88 }
89 inline agx::Physics::Geometry::SpherePtr Sphere::getEntity() const
90 {
91 return m_entity;
92 }
93 AGX_FORCE_INLINE BoundingAABB Sphere::calculateBound(const agx::AffineMatrix4x4& transform, agx::Real radius)
94 {
95 const agx::Vec3 pos = transform.getTranslate();
96 const agx::Vec3 halfExtents = agx::Vec3(radius);
97 const BoundingAABB bound = BoundingAABB(pos - halfExtents, pos + halfExtents);
98 return bound;
99 }
100
101 AGX_FORCE_INLINE agx::Real Sphere::calculateVolume(agx::Real radius)
102 {
103 // 4 pi r^3 / 3
104 return radius * radius * radius * (agx::Real(4) * agx::PI / agx::Real(3));
105 }
106
107}
108
109#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
#define AGXPHYSICS_EXPORT
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Base class for a shape.
Definition: Shape.h:58
A sphere class for geometric intersection tests.
Definition: Sphere.h:32
virtual Shape * clone() const override
Create a clone.
virtual agx::Vec3 getSupportPoint(const agx::Vec3 &supportDirection) const override
Returns the support point on face of the shape.
virtual agx::Real getVolume() const override
Return the volume of the shape.
virtual BoundingAABB calculateLocalBound() const override
Calculate the bounding volume in the local coordinate system.
virtual const BoundingAABB & updateBoundingVolume() override
Calculate the bounding volume based on the current Shape parameters including transformation.
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Calculate the inertia for the shape given a mass.
Sphere(agx::Real radius=agx::Real(0.5))
Constructor.
virtual bool hasSupportFunction() const override
void setRadius(agx::Real radius)
Set the sphere radius.
virtual agx::Real calculateBoundingRadius(BoundingAABB &localAABB) const override
Calculate the bounding volume (AABB) into localAABB and calculate the bounding radius based on the ne...
Pointer to a entity instance of type Physics.Geometry.Sphere.
Definition: SphereEntity.h:161
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
static constexpr Real PI
Definition: Math.h:63
double Real
Definition: Real.h:41