AGX Dynamics  2.37.2.0
ollide/Plane.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXCOLLIDE_PLANE_H
18 #define AGXCOLLIDE_PLANE_H
19 
20 #include <agx/Vec4.h>
21 #include <agxCollide/Shape.h>
23 
24 namespace agxCollide
25 {
26 
34  class AGXPHYSICS_EXPORT Plane : public Shape
35  {
36  public:
37 
41  Plane();
42 
46  Plane( agx::Real const a, agx::Real const b, agx::Real const c, agx::Real d );
47 
53  Plane( const agx::Vec3 normal, agx::Real d );
54 
60  Plane( const agx::Vec3 normal, const agx::Vec3 point );
61 
62  Plane( const agx::Vec4 plane);
63 
67  Plane( const agx::Vec3 p1, const agx::Vec3 p2, const agx::Vec3 p3);
68 
69  void set( const agx::Vec4& plane );
70  void set(const agx::Vec3& p1, const agx::Vec3& p2, const agx::Vec3& p3);
71 
72  virtual agx::Real getVolume() const override;
73 
74  agx::Vec4 asVec4() const;
75 
77  const agx::Vec3 getNormal() const;
78 
80  agx::Real getDistance() const;
81 
83  void setNormal( const agx::Vec3& normal );
84 
86  void setDistance( agx::Real distance );
87 
88  agx::Vec4 calculatePlane( const agx::AffineMatrix4x4& transform ) const;
89 
93  agx::Real signedDistanceToPoint( const agx::Vec3& point ) const;
94 
95  virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
96  virtual const BoundingAABB& updateBoundingVolume() override;
97  virtual BoundingAABB calculateLocalBound() const override;
98 
99  static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, const agx::Plane& plane);
100 
104  virtual Shape *clone() const override;
105 
107 
109 
110  protected:
111  Plane& operator=(const Plane&) { return *this; }
112  virtual ~Plane();
113 
114  private:
115  void init(const agx::Vec3& normal, agx::Real distance);
116  };
117 
118 
119  /* Implementation */
120  inline agx::Physics::Geometry::PlanePtr Plane::getEntity() const { return m_entity; }
121 
122  AGX_FORCE_INLINE const agx::Vec3 Plane::getNormal() const { return getEntity().plane().getNormal(); }
123  AGX_FORCE_INLINE agx::Real Plane::getDistance() const { return getEntity().plane().getDistance(); }
124 
126  {
127  return ( getNormal() * point ) + getDistance();
128  }
129 
130 
132  {
133  BoundingAABB localbound;
134 
135  localbound.max() = agx::Vec3( agx::RealMax - 1, agx::RealMax - 1, agx::RealMax - 1 );
136  localbound.min() = agx::Vec3( -agx::RealMax + 1, -agx::RealMax + 1, -agx::RealMax + 1 );
137 
138  /*
139  Disabled, until #1935 is fixed.
140 
141  // make bounding box smaller in case the normal is aligned to natural axis
142  for (int i = 0; i < 3; ++i) {
143  if (plane.getNormal()[i] == 1) {
144  localbound.max[i] = -plane.getDistance();
145  break;
146  }
147  else if (plane.getNormal()[i] == -1) {
148  localbound.min[i] = -plane.getDistance();
149  break;
150  }
151  }
152  */
153 
154  return BoundingAABB(localbound, transform);
155  }
156 }
157 
158 
159 #endif
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
Base class for a shape.
Definition: Shape.h:53
agx::Real getDistance() const
Get the distance d (from plane equation ax+by+cz+d=0).
Definition: ollide/Plane.h:123
This namespace consists of a set of classes for handling geometric intersection tests including boole...
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
PlaneT< agx::Real > Plane
Definition: Plane.h:121
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
const T & max() const
Definition: Bound.h:255
#define AGXPHYSICS_EXPORT
agx::Real signedDistanceToPoint(const agx::Vec3 &point) const
Calculates the distance from the plane to a point.
Definition: ollide/Plane.h:125
#define AGX_FORCE_INLINE
Definition: Object.h:59
Class representing the mathematical concept of a plane, also called a half- space.
Definition: Plane.h:31
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Pointer to a entity instance of type Physics.Geometry.Plane.
Definition: PlaneEntity.h:160
const T & min() const
Definition: Bound.h:252
#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
static BoundingAABB calculateBound(const agx::AffineMatrix4x4 &transform, const agx::Plane &plane)
Definition: ollide/Plane.h:131
AGXCORE_EXPORT const Real RealMax
Plane & operator=(const Plane &)
Definition: ollide/Plane.h:111
double Real
Definition: Real.h:42
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
agx::Physics::Geometry::PlanePtr getEntity() const
Definition: ollide/Plane.h:120
AGX_DECLARE_POINTER_TYPES(SpaceListener)
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
const agx::Vec3 getNormal() const
Get the normal (a, b, c) from plane equation ax+by+cz+d=0.
Definition: ollide/Plane.h:122