Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Geometry where
- data Point = Pt {
- pointX :: Double,
- pointY :: Double
- } deriving Show
- data Vector = Vec {
- vectorX :: Double,
- vectorY :: Double
- } deriving Show
- data SourcedVector = SVec {
- vectorSource :: Point,
- vectorDirection :: Vector
- } deriving Show
- data PlaneVector = PVec {
- planeFrom :: Point,
- planeTo :: Point
- } deriving Show
- sourcedToPlane :: SourcedVector -> PlaneVector
- sourcedToPlane (SVec (Pt fx fy) (Vec dx dy)) =
- (PVec (Pt fx fy) (Pt (fx + dx) (fy + dy)))
- planeToSourced :: PlaneVector -> SourcedVector
- planeToSourced (PVec (Pt fx fy) (Pt tx ty)) =
- (SVec (Pt fx fy) (Vec (tx - fx) (ty - fy)))
- makeSourced :: Point -> Point -> SourcedVector
- makeSourced f t = planeToSourced (PVec f t)
- dest :: SourcedVector -> Point
- dest (SVec (Pt fx fy) (Vec dx dy)) = Pt (fx + dx) (fy + dy)
- dist :: Point -> Point -> Double
- dist (Pt a b) (Pt c d) = sqrt ((a - c) * (a - c) + (b - d) * (b - d))
- mult :: SourcedVector -> Double -> SourcedVector
- mult (SVec s (Vec dx dy)) a = (SVec s newDirection)
- where newDirection = Vec (a*dx) (a*dy)
- alpha :: SourcedVector -> Point -> Double
- alpha (SVec (Pt x _) (Vec dx _)) (Pt a _) = (a - x) / dx
- scp :: Vector -> Vector -> Double
- scp (Vec fx fy) (Vec sx sy) = fx * sx + fy * sy
- vcp :: Vector -> Vector -> Double
- vcp (Vec x y) (Vec a b) = x * b - y * a
- a = (Pt 2.0 2.0)
- b = (Pt 6.0 10.0)
- c = (Pt 7.0 4.0)
- d = (Pt 4.0 6.0)
- u = makeSourced a b
- v = makeSourced c d
- e = (Pt 3 (-1))
- f = (Pt 7 2)
- g = Pt 14 4
- h = Pt 16 10
- i = Pt 20 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement