module Graphics.Gloss.Data.Vector
( Vector
, magV
, argV
, dotV
, detV
, mulSV
, rotateV
, angleVV
, normaliseV
, unitVectorAtAngle )
where
import Graphics.Gloss.Data.Point
import Graphics.Gloss.Geometry.Angle
type Vector = Point
magV :: Vector -> Float
magV (x, y)
= sqrt (x * x + y * y)
argV :: Vector -> Float
argV (x, y)
= normaliseAngle $ atan2 y x
dotV :: Vector -> Vector -> Float
dotV (x1, x2) (y1, y2)
= x1 * y1 + x2 * y2
detV :: Vector -> Vector -> Float
detV (x1, y1) (x2, y2)
= x1 * y2 y1 * x2
mulSV :: Float -> Vector -> Vector
mulSV s (x, y)
= (s * x, s * y)
rotateV :: Float -> Vector -> Vector
rotateV r (x, y)
= ( x * cos r y * sin r
, x * sin r + y * cos r)
angleVV :: Vector -> Vector -> Float
angleVV p1 p2
= let m1 = magV p1
m2 = magV p2
d = p1 `dotV` p2
aDiff = acos $ d / (m1 * m2)
in aDiff
normaliseV :: Vector -> Vector
normaliseV v = mulSV (1 / magV v) v
unitVectorAtAngle :: Float -> Vector
unitVectorAtAngle r
= (cos r, sin r)