Skip to content

Commit

Permalink
Add crossZ (Z-component of cross product) for V2
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEichmann committed May 21, 2016
1 parent 59d93de commit 982a7bb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Linear/V2.hs
Expand Up @@ -39,6 +39,7 @@ module Linear.V2
, ex, ey
, perp
, angle
, crossZ
) where

import Control.Applicative
Expand Down Expand Up @@ -391,6 +392,14 @@ instance MonadFix V2 where
angle :: Floating a => a -> V2 a
angle a = V2 (cos a) (sin a)

-- | The Z-component of the cross product of two vectors in the XY-plane.
--
-- >>> crossZ (V2 1 0) (V2 0 1)
-- 1
crossZ :: Num a => V2 a -> V2 a -> a
crossZ (V2 x1 y1) (V2 x2 y2) = (x1 * y2) - (y1 * x2)
{-# INLINE crossZ #-}

instance Bounded a => Bounded (V2 a) where
minBound = pure minBound
{-# INLINE minBound #-}
Expand Down

0 comments on commit 982a7bb

Please sign in to comment.