Created
December 14, 2019 08:50
-
-
Save yasar11732/083d86af4efa17acb56222749a19d1f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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