Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Consider three two-dimensional points a, b, and c. If we look at the angle
- --formed by the line segment from a to b and the line segment from b to c,
- --it either turns left, turns right, or forms a straight line.
- --Define a Direction data type that lets you represent these possibilities.
- data Direction a = ToRight
- | ToLeft
- | ToStraight
- | None
- deriving (Eq, Show)
- -- Write a function that calculates the turn made by three 2D points and returns a Direction.
- dirCalc :: Ord a => Fractional a => Eq a => Num a => (a, a) -> (a, a) -> (a, a) -> Direction a
- dirCalc (0,0) (0,0) (0,0) = None
- dirCalc (x1, y1) (x2, y2) (x3, y3) = if k1 > k2 then ToRight
- else if k1 == k2 then ToStraight
- else ToLeft
- where k1 = (y2 - y1) / (x2 - x1)
- k2 = (y3 - y2) / (x3 - x2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement