TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Plane Class Reference

#include <Plane.h>

Public Member Functions

 Plane ()
 
 Plane (const class Any &a)
 
Any toAny () const
 
 Plane (const Point3 &point0, const Point3 &point1, const Point3 &point2)
 
 Plane (Vector4 point0, Vector4 point1, Vector4 point2)
 
 Plane (const Vector3 &normal, const Point3 &point)
 
 Plane (class BinaryInput &b)
 
void serialize (class BinaryOutput &b) const
 
void deserialize (class BinaryInput &b)
 
virtual ~Plane ()
 
bool halfSpaceContains (Point3 point) const
 
bool halfSpaceContains (const Vector4 &point) const
 
bool halfSpaceContainsFinite (const Point3 &point) const
 
bool fuzzyContains (const Point3 &point) const
 
const Vector3 & normal () const
 
float distance (const Vector3 &x) const
 
Point3 closestPoint (const Point3 &x) const
 
Vector3 center () const
 
void flip ()
 
void getEquation (Vector3 &normal, double &d) const
 
void getEquation (Vector3 &normal, float &d) const
 
void getEquation (double &a, double &b, double &c, double &d) const
 
void getEquation (float &a, float &b, float &c, float &d) const
 
std::string toString () const
 

Static Public Member Functions

static Plane fromEquation (float a, float b, float c, float d)
 

Private Member Functions

 Plane (const Vector3 &n, float d)
 

Private Attributes

Vector3 _normal
 
float _distance
 

Detailed Description

An infinite 2D plane in 3D space.

Constructor & Destructor Documentation

G3D::Plane::Plane ( const Vector3 &  n,
float  d 
)
inlineprivate

Assumes the normal has unit length.

35  : _normal(n), _distance(d) {
36  }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
G3D::Plane::Plane ( )
inline
41  }
float _distance
Definition: Plane.h:30
static const Vector3 & unitY()
Definition: Vector3.cpp:122
Vector3 _normal
Definition: Plane.h:29

+ Here is the caller graph for this function:

G3D::Plane::Plane ( const class Any &  a)
explicit

Format is:

  • Plane(normal, point)
G3D::Plane::Plane ( const Point3 &  point0,
const Point3 &  point1,
const Point3 &  point2 
)

Constructs a plane from three points.

101  {
102 
103  _normal = (point1 - point0).cross(point2 - point0).direction();
104  _distance = _normal.dot(point0);
105 }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 direction() const
Definition: Vector3.h:756
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
Vector3 cross(const Vector3 &v1, const Vector3 &v2)
Definition: vectorMath.h:144

+ Here is the call graph for this function:

G3D::Plane::Plane ( Vector4  point0,
Vector4  point1,
Vector4  point2 
)

Constructs a plane from three points, where at most two are at infinity (w = 0, not xyz = inf).

54  {
55 
57  point0.w != 0 ||
58  point1.w != 0 ||
59  point2.w != 0,
60  "At least one point must be finite.");
61 
62  // Rotate the points around so that the finite points come first.
63 
64  while ((point0.w == 0) &&
65  ((point1.w == 0) || (point2.w != 0))) {
66  Vector4 temp = point0;
67  point0 = point1;
68  point1 = point2;
69  point2 = temp;
70  }
71 
72  Vector3 dir1;
73  Vector3 dir2;
74 
75  if (point1.w == 0) {
76  // 1 finite, 2 infinite points; the plane must contain
77  // the direction of the two direcitons
78  dir1 = point1.xyz();
79  dir2 = point2.xyz();
80  } else if (point2.w != 0) {
81  // 3 finite points, the plane must contain the directions
82  // betwseen the points.
83  dir1 = point1.xyz() - point0.xyz();
84  dir2 = point2.xyz() - point0.xyz();
85  } else {
86  // 2 finite, 1 infinite point; the plane must contain
87  // the direction between the first two points and the
88  // direction of the third point.
89  dir1 = point1.xyz() - point0.xyz();
90  dir2 = point2.xyz();
91  }
92 
93  _normal = dir1.cross(dir2).direction();
94  _distance = _normal.dot(point0.xyz());
95 }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
Vector3 direction() const
Definition: Vector3.h:756
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
Vector3 __fastcall cross(const Vector3 &rkVector) const
Definition: Vector3.h:776

+ Here is the call graph for this function:

G3D::Plane::Plane ( const Vector3 &  normal,
const Point3 &  point 
)

The normal will be unitized.

110  {
111 
112  _normal = __normal.direction();
113  _distance = _normal.dot(point);
114 }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 direction() const
Definition: Vector3.h:756
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29

+ Here is the call graph for this function:

G3D::Plane::Plane ( class BinaryInput &  b)
34  {
35  deserialize(b);
36 }
void deserialize(class BinaryInput &b)
Definition: Plane.cpp:45

+ Here is the call graph for this function:

virtual G3D::Plane::~Plane ( )
inlinevirtual
81 {}

Member Function Documentation

Vector3 G3D::Plane::center ( ) const
inline

Returns normal * distance from origin

140  {
141  return _normal * _distance;
142  }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
Point3 G3D::Plane::closestPoint ( const Point3 &  x) const
inline
135  {
136  return x + (_normal * (-distance(x)));
137  }
Vector3 _normal
Definition: Plane.h:29
float distance(const Vector3 &x) const
Definition: Plane.h:131
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Plane::deserialize ( class BinaryInput &  b)
45  {
47  _distance = (float)b.readFloat64();
48 }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
void deserialize(class BinaryInput &b)
Definition: Vector3.cpp:190

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float G3D::Plane::distance ( const Vector3 &  x) const
inline

Returns distance from point to plane. Distance is negative if point is behind (not in plane in direction opposite normal) the plane.

131  {
132  return (_normal.dot(x) - _distance);
133  }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Plane::flip ( )

Inverts the facing direction of the plane so the new normal is the inverse of the old normal.

126  {
127  _normal = -_normal;
128  _distance = -_distance;
129 }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
Plane G3D::Plane::fromEquation ( float  a,
float  b,
float  c,
float  d 
)
static
117  {
118  Vector3 n(a, b, c);
119  float magnitude = n.magnitude();
120  d /= magnitude;
121  n /= magnitude;
122  return Plane(n, -d);
123 }
Plane()
Definition: Plane.h:40

+ Here is the call graph for this function:

bool G3D::Plane::fuzzyContains ( const Point3 &  point) const
inline

Returns true if the point is nearly in the plane.

120  {
121  return fuzzyEq(point.dot(_normal), _distance);
122  }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::Plane::getEquation ( Vector3 &  normal,
double &  d 
) const

Returns the equation in the form:

normal.Dot(Vector3(x, y, z)) + d = 0

138  {
139  n = _normal;
140  d = -_distance;
141 }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29

+ Here is the caller graph for this function:

void G3D::Plane::getEquation ( Vector3 &  normal,
float &  d 
) const
132  {
133  double _d;
134  getEquation(n, _d);
135  d = (float)_d;
136 }
void getEquation(Vector3 &normal, double &d) const
Definition: Plane.cpp:138

+ Here is the call graph for this function:

void G3D::Plane::getEquation ( double &  a,
double &  b,
double &  c,
double &  d 
) const

ax + by + cz + d = 0

153  {
154  a = _normal.x;
155  b = _normal.y;
156  c = _normal.z;
157  d = -_distance;
158 }
float x
Definition: Vector3.h:62
float _distance
Definition: Plane.h:30
float y
Definition: Vector3.h:62
Vector3 _normal
Definition: Plane.h:29
float z
Definition: Vector3.h:62
void G3D::Plane::getEquation ( float &  a,
float &  b,
float &  c,
float &  d 
) const
144  {
145  double _a, _b, _c, _d;
146  getEquation(_a, _b, _c, _d);
147  a = (float)_a;
148  b = (float)_b;
149  c = (float)_c;
150  d = (float)_d;
151 }
void getEquation(Vector3 &normal, double &d) const
Definition: Plane.cpp:138

+ Here is the call graph for this function:

bool G3D::Plane::halfSpaceContains ( Point3  point) const
inline

Returns true if point is on the side the normal points to or is in the plane.

87  {
88  // Clamp to a finite range for testing
89  point = point.clamp(Vector3::minFinite(), Vector3::maxFinite());
90 
91  // We can get away with putting values *at* the limits of the float32 range into
92  // a dot product, since the dot product is carried out on float64.
93  return _normal.dot(point) >= _distance;
94  }
static const Vector3 & minFinite()
Definition: Vector3.cpp:126
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
static const Vector3 & maxFinite()
Definition: Vector3.cpp:127

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Plane::halfSpaceContains ( const Vector4 &  point) const
inline

Returns true if point is on the side the normal points to or is in the plane.

100  {
101  if (point.w == 0) {
102  return _normal.dot(point.xyz()) > 0;
103  } else {
104  return halfSpaceContains(point.xyz() / point.w);
105  }
106  }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
Vector3 _normal
Definition: Plane.h:29
bool halfSpaceContains(Point3 point) const
Definition: Plane.h:87

+ Here is the call graph for this function:

bool G3D::Plane::halfSpaceContainsFinite ( const Point3 &  point) const
inline

Returns true if point is on the side the normal points to or is in the plane. Only call on finite points. Faster than halfSpaceContains.

112  {
113  debugAssert(point.isFinite());
114  return _normal.dot(point) >= _distance;
115  }
float __fastcall dot(const Vector3 &rkVector) const
Definition: Vector3.h:771
float _distance
Definition: Plane.h:30
#define debugAssert(exp)
Definition: debugAssert.h:160
Vector3 _normal
Definition: Plane.h:29

+ Here is the call graph for this function:

const Vector3& G3D::Plane::normal ( ) const
inline
124  {
125  return _normal;
126  }
Vector3 _normal
Definition: Plane.h:29

+ Here is the caller graph for this function:

void G3D::Plane::serialize ( class BinaryOutput &  b) const
39  {
40  _normal.serialize(b);
41  b.writeFloat64(_distance);
42 }
float _distance
Definition: Plane.h:30
Vector3 _normal
Definition: Plane.h:29
void serialize(class BinaryOutput &b) const
Definition: Vector3.cpp:219

+ Here is the call graph for this function:

Any G3D::Plane::toAny ( ) const
27  {
28  Any a(Any::ARRAY, "Plane");
29  a.append(normal(), normal() * _distance);
30  return a;
31 }
const Vector3 & normal() const
Definition: Plane.h:124
Definition: Any.h:187
float _distance
Definition: Plane.h:30

+ Here is the call graph for this function:

std::string G3D::Plane::toString ( ) const
161  {
162  return format("Plane(%g, %g, %g, %g)", _normal.x, _normal.y, _normal.z, _distance);
163 }
float x
Definition: Vector3.h:62
float _distance
Definition: Plane.h:30
float y
Definition: Vector3.h:62
Vector3 _normal
Definition: Plane.h:29
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float z
Definition: Vector3.h:62

+ Here is the call graph for this function:

Member Data Documentation

float G3D::Plane::_distance
private
Vector3 G3D::Plane::_normal
private

normal.Dot(x,y,z) = distance


The documentation for this class was generated from the following files: