AGX Dynamics  2.35.0.1
agxCollide/Plane.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
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 */
121 
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
#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
agx::Physics::Geometry::PlanePtr getEntity() const
virtual Shape * clone() const override
Create a clone.
agx::Vec4 calculatePlane(const agx::AffineMatrix4x4 &transform) const
Plane()
Default constructor.
void setDistance(agx::Real distance)
Set the distance d (from plane equation ax+by+cz+d=0).
Plane(agx::Real const a, agx::Real const b, agx::Real const c, agx::Real d)
Constructor, using plane equation ax+by+cz+d=0.
void set(const agx::Vec3 &p1, const agx::Vec3 &p2, const agx::Vec3 &p3)
static BoundingAABB calculateBound(const agx::AffineMatrix4x4 &transform, const agx::Plane &plane)
Plane(const agx::Vec3 p1, const agx::Vec3 p2, const agx::Vec3 p3)
Create a plane which is spanned using three distinct points.
void set(const agx::Vec4 &plane)
Plane & operator=(const Plane &)
virtual agx::Real getVolume() const override
Return the volume of the shape.
agx::Real signedDistanceToPoint(const agx::Vec3 &point) const
Calculates the distance from the plane to a point.
agx::Vec4 asVec4() const
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override
Calculate the inertia for the shape given a mass.
virtual BoundingAABB calculateLocalBound() const override
Calculate the bounding volume in the local coordinate system.
Plane(const agx::Vec3 normal, const agx::Vec3 point)
Constructor.
void setNormal(const agx::Vec3 &normal)
Set the normal (a, b, c) from plane equation ax+by+cz+d=0.
agx::Real getDistance() const
Get the distance d (from plane equation ax+by+cz+d=0).
const agx::Vec3 getNormal() const
Get the normal (a, b, c) from plane equation ax+by+cz+d=0.
Plane(const agx::Vec4 plane)
Plane(const agx::Vec3 normal, agx::Real d)
Constructor.
virtual const BoundingAABB & updateBoundingVolume() override
Calculate the bounding volume based on the current Shape parameters including transformation.
Base class for a shape.
Definition: Shape.h:54
agx::Physics::Geometry::ShapeRef m_entity
Definition: Shape.h:266
const T & min() const
Definition: Bound.h:252
const T & max() const
Definition: Bound.h:255
Pointer to a entity instance of type Physics.Geometry.Plane.
Definition: PlaneEntity.h:161
AGXPHYSICS_EXPORT agx::Plane & plane()
Class representing the mathematical concept of a plane, also called a half- space.
Definition: agx/Plane.h:32
T getDistance() const
Definition: agx/Plane.h:194
agx::Vec3T< T > getNormal() const
/return The normal of the plane.
Definition: agx/Plane.h:191
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:49
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
AGX_DECLARE_POINTER_TYPES(SpaceListener)
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
AGXCORE_EXPORT const Real RealMax
double Real
Definition: Real.h:42
void AGXPHYSICS_EXPORT init()
Initialize agx.