SOE ex.8.5


data Region = HalfPlane Coordinate Coordinate
type Coordinate = (Float, Float)

containsR :: Region -> Coordinate -> Bool
HalfPlane p1 p2 `containsR` p = p `isLeftOf` (p1, p2)

----- reuse the isLeftOf function -----
isLeftOf :: Coordinate -> Ray -> Bool
(px, py) `isLeftOf` ((ax, ay), (bx, by))
  = let (s, t) = (px - ax, py - ay)
        (u, v) = (px - bx, py - by)
    in s * v >= t * u

type Ray = (Coordinate, Coordinate)

Leave a Reply