4 @maintainer Morgan McGuire, matrix@graphics3d.com
10 #include "G3D/platform.h"
11 #include "G3D/format.h"
12 #include "G3D/Plane.h"
13 #include "G3D/stringutils.h"
26 "At least one point must be finite.");
28 // Rotate the points around so that the finite points come first.
30 while ((point0
.w
== 0) &&
31 ((point1
.w
== 0) || (point2
.w
!= 0))) {
32 Vector4 temp
= point0
;
42 // 1 finite, 2 infinite points; the plane must contain
43 // the direction of the two direcitons
46 } else if (point2
.w
!= 0) {
47 // 3 finite points, the plane must contain the directions
48 // betwseen the points.
49 dir1
= point1
.xyz() - point0
.xyz();
50 dir2
= point2
.xyz() - point0
.xyz();
52 // 2 finite, 1 infinite point; the plane must contain
53 // the direction between the first two points and the
54 // direction of the third point.
55 dir1
= point1
.xyz() - point0
.xyz();
59 _normal
= dir1
.cross(dir2
).direction();
60 _distance
= _normal
.dot(point0
.xyz());
65 const Vector3
& point0
,
66 const Vector3
& point1
,
67 const Vector3
& point2
) {
69 _normal
= (point1
- point0
).cross(point2
- point0
).direction();
70 _distance
= _normal
.dot(point0
);
75 const Vector3
& __normal
,
76 const Vector3
& point
) {
78 _normal
= __normal
.direction();
79 _distance
= _normal
.dot(point
);
83 Plane
Plane::fromEquation(float a
, float b
, float c
, float d
) {
85 float magnitude
= n
.magnitude();
94 _distance
= -_distance
;
98 void Plane::getEquation(Vector3
& n
, float& d
) const {
104 void Plane::getEquation(Vector3
& n
, double& d
) const {
110 void Plane::getEquation(float& a
, float& b
, float& c
, float& d
) const {
111 double _a
, _b
, _c
, _d
;
112 getEquation(_a
, _b
, _c
, _d
);
119 void Plane::getEquation(double& a
, double& b
, double& c
, double& d
) const {
127 std::string
Plane::toString() const {
128 return format("Plane(%g, %g, %g, %g)", _normal
.x
, _normal
.y
, _normal
.z
, _distance
);