IcePlane.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICEPLANE_H__
13 #define __ICEPLANE_H__
14 
15  #define PLANE_EPSILON (1.0e-7f)
16 
18  {
19  public:
21  inline_ Plane() { }
23  inline_ Plane(float nx, float ny, float nz, float d) { Set(nx, ny, nz, d); }
25  inline_ Plane(const Point& p, const Point& n) { Set(p, n); }
27  inline_ Plane(const Point& p0, const Point& p1, const Point& p2) { Set(p0, p1, p2); }
29  inline_ Plane(const Point& _n, float _d) { n = _n; d = _d; }
31  inline_ Plane(const Plane& plane) : n(plane.n), d(plane.d) { }
34 
35  inline_ Plane& Zero() { n.Zero(); d = 0.0f; return *this; }
36  inline_ Plane& Set(float nx, float ny, float nz, float _d) { n.Set(nx, ny, nz); d = _d; return *this; }
37  inline_ Plane& Set(const Point& p, const Point& _n) { n = _n; d = - p | _n; return *this; }
38  Plane& Set(const Point& p0, const Point& p1, const Point& p2);
39 
40  inline_ float Distance(const Point& p) const { return (p | n) + d; }
41  inline_ bool Belongs(const Point& p) const { return fabsf(Distance(p)) < PLANE_EPSILON; }
42 
44  {
45  float Denom = 1.0f / n.Magnitude();
46  n.x *= Denom;
47  n.y *= Denom;
48  n.z *= Denom;
49  d *= Denom;
50  }
51  public:
52  // Members
53  Point n;
54  float d;
55 
56  // Cast operators
57  inline_ operator Point() const { return n; }
58  inline_ operator HPoint() const { return HPoint(n, d); }
59 
60  // Arithmetic operators
61  inline_ Plane operator*(const Matrix4x4& m) const
62  {
63  // Old code from Irion. Kept for reference.
64  Plane Ret(*this);
65  return Ret *= m;
66  }
67 
69  {
70  // Old code from Irion. Kept for reference.
71  Point n2 = HPoint(n, 0.0f) * m;
72  d = -((Point) (HPoint( -d*n, 1.0f ) * m) | n2);
73  n = n2;
74  return *this;
75  }
76  };
77 
79 
86  inline_ void TransformPlane(Plane& transformed, const Plane& plane, const Matrix4x4& transform)
88  {
89  // Rotate the normal using the rotation part of the 4x4 matrix
90  transformed.n = plane.n * Matrix3x3(transform);
91 
92  // Compute new d
93  transformed.d = plane.d - (Point(transform.GetTrans())|transformed.n);
94  }
95 
97 
103  inline_ void TransformPlane(Plane& plane, const Matrix4x4& transform)
105  {
106  // Rotate the normal using the rotation part of the 4x4 matrix
107  plane.n *= Matrix3x3(transform);
108 
109  // Compute new d
110  plane.d -= Point(transform.GetTrans())|plane.n;
111  }
112 
113 #endif // __ICEPLANE_H__
inline_ Plane(const Point &p0, const Point &p1, const Point &p2)
Constructor from three points.
Definition: IcePlane.h:27
inline_ Plane(float nx, float ny, float nz, float d)
Constructor from a normal and a distance.
Definition: IcePlane.h:23
inline_ Plane()
Constructor.
Definition: IcePlane.h:21
inline_ bool Belongs(const Point &p) const
Definition: IcePlane.h:41
#define inline_
float d
The distance from the origin.
Definition: IcePlane.h:54
Definition: IcePoint.h:25
#define ICEMATHS_API
Definition: OPC_IceHook.h:51
Definition: IcePlane.h:17
inline_ Plane & Zero()
Definition: IcePlane.h:35
inline_ float Distance(const Point &p) const
Definition: IcePlane.h:40
inline_ Plane & Set(const Point &p, const Point &_n)
Definition: IcePlane.h:37
Point n
The normal to the plane.
Definition: IcePlane.h:53
inline_ Plane operator*(const Matrix4x4 &m) const
Definition: IcePlane.h:61
inline_ ~Plane()
Destructor.
Definition: IcePlane.h:33
inline_ Plane(const Plane &plane)
Copy constructor.
Definition: IcePlane.h:31
inline_ Plane(const Point &_n, float _d)
Constructor from a normal and a distance.
Definition: IcePlane.h:29
#define PLANE_EPSILON
Definition: OPC_IceHook.h:16
inline_ Plane & operator*=(const Matrix4x4 &m)
Definition: IcePlane.h:68
inline_ Plane(const Point &p, const Point &n)
Constructor from a point on the plane and a normal.
Definition: IcePlane.h:25
inline_ void TransformPlane(Plane &transformed, const Plane &plane, const Matrix4x4 &transform)
Definition: IcePlane.h:87
inline_ void Normalize()
Definition: IcePlane.h:43
inline_ const HPoint & GetTrans() const
Returns the translation part of the matrix.
Definition: IceMatrix4x4.h:95
inline_ Plane & Set(float nx, float ny, float nz, float _d)
Definition: IcePlane.h:36


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:03