]>
Dogcows Code - chaz/yoink/blob - src/moof/plane.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_PLANE_HH_
13 #define _MOOF_PLANE_HH_
17 * Classes and functions related to planes.
20 #include <moof/math.hh>
21 #include <moof/shape.hh>
27 template <int D
> class aabb
;
28 template <int D
> class sphere
;
32 * A plane in 3-space defined by the equation Ax + By + Cz = D, where [A,
33 * B, C] is normal to the plane.
35 struct plane
: public shape
<3>
48 plane(const vector3
& vector
, scalar scalar
) :
51 plane(scalar a
, scalar b
, scalar c
, scalar scalar
) :
56 bool intersect_ray(const ray3
& ray
, ray3::contact
& hit
)
58 // solve: [(ray.point + t*ray.direction) dot normal] + d = 0
60 scalar denom
= dot(ray
.direction
, normal
);
62 // check for parallel condition
63 if (denom
== SCALAR(0.0))
65 if (is_equal(dot(ray
.point
, normal
), -d
))
67 // the ray lies on the plane
68 hit
.distance
= SCALAR(0.0);
69 hit
.normal
.set(0.0, 0.0, 0.0);
77 scalar numer
= dot(ray
.point
, normal
) + d
;
78 hit
.distance
= -numer
/ denom
;
79 if (hit
.distance
< SCALAR(0.0)) return false;
81 if (numer
>= 0.0) hit
.normal
= normal
;
82 else hit
.normal
= -normal
;
87 /* Causes the normal of the plane to become normalized. The scalar may
88 * also be changed to keep the equation true. Word to the wise: don't
89 * normalize a plane if the normal is the zero vector.
93 scalar mag
= normal
.length();
100 * Determine the shortest distance between a point and the plane.
102 scalar
distance_to_point(const vector3
& point
) const
104 return dot(point
, normal
) + d
;
107 halfspace
intersects(const vector3
& point
) const
109 scalar distance
= distance_to_point(point
);
111 if (is_equal(distance
, 0.0)) return intersecting
;
112 else if (distance
< 0.0) return negative
;
113 else return positive
;
116 halfspace
intersects(const aabb
<3>& aabb
) const;
117 halfspace
intersects(const sphere
<3>& sphere
) const;
123 #endif // _MOOF_PLANE_HH_
This page took 0.048185 seconds and 4 git commands to generate.