aboutsummaryrefslogtreecommitdiff
path: root/Spear/Math/Plane.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Spear/Math/Plane.hs')
-rw-r--r--Spear/Math/Plane.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Spear/Math/Plane.hs b/Spear/Math/Plane.hs
new file mode 100644
index 0000000..0f5829b
--- /dev/null
+++ b/Spear/Math/Plane.hs
@@ -0,0 +1,33 @@
1module Spear.Math.Plane
2(
3 Plane
4, plane
5, classify
6)
7where
8
9
10import Spear.Math.Vector3 as Vector
11
12
13data PointPlanePos = Front | Back | Contained deriving (Eq, Ord, Show)
14
15
16data Plane = Plane {
17 n :: !Vector3,
18 d :: !Float
19} deriving(Eq, Show)
20
21
22-- | Create a plane given a normal vector and a distance from the origin.
23plane :: Vector3 -> Float -> Plane
24plane n d = Plane (normalise n) d
25
26
27-- | Classify the given point's relative position with respect to the given plane.
28classify :: Plane -> Vector3 -> PointPlanePos
29classify (Plane n d) pt = case (n `dot` pt - d) `compare` 0 of
30 GT -> Front
31 LT -> Back
32 EQ -> Contained
33 \ No newline at end of file