Skip to content

Instantly share code, notes, and snippets.

@yasar11732
Created December 14, 2019 08:50
Show Gist options
  • Save yasar11732/083d86af4efa17acb56222749a19d1f8 to your computer and use it in GitHub Desktop.
Save yasar11732/083d86af4efa17acb56222749a19d1f8 to your computer and use it in GitHub Desktop.
module Hull where
data Direction = L | R | S
instance Show Direction where
show L = "Left"
show R = "Right"
show S = "Straight"
data Point = Point Float Float
slope :: Point -> Point -> Float
slope (Point ax ay) (Point bx by) = (by - ay) / (bx-ax)
crossProduct :: Point -> Point -> Float
crossProduct (Point ax ay) (Point bx by) = (ax * by) - (ay * bx)
turn :: Point -> Point -> Point ->Direction
turn (Point ax ay) (Point bx by) (Point cx cy) =
let p1 = Point (ax - bx) (ay - by) -- Move dots so that point B is in origion
p3 = Point (cx - bx) (cy - by)
c = crossProduct p1 p3
in case compare c 0 of
GT -> R
LT -> L
_ -> S
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment