Skip to content

Commit

Permalink
Moved 3D rotation matrices from ...Matrix.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbm committed Apr 8, 2011
1 parent 3810fd5 commit 04521bd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Rotation.hs
@@ -0,0 +1,44 @@
{-# LANGUAGE TypeOperators #-}

module Rotation where

import Data.HList ((:*:))
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.LinearAlgebra
import qualified Prelude

-- | The type of homogenous vectors with three elements.
type Homo3 d = Vec (d:*:d:*.d)

-- | Cartesian unit vectors.
unit_x, unit_y, unit_z :: Num a => Homo3 DOne a
unit_x = vCons _1 $ vCons _0 $ vSing _0
unit_y = vCons _0 $ vCons _1 $ vSing _0
unit_z = vCons _0 $ vCons _0 $ vSing _1


-- Rotation matrices (cartesian)
-- =============================

-- | Convenience type for homogeneous 3x3 matrices.
type Homo33 d = Mat ((d:*:d:*.d) :*:
(d:*:d:*.d) :*.
(d:*:d:*.d))

-- Rotation matrices. Rotates a vector by the given angle (analogous
-- to rotating the coordinate system in opposite direction).

rotX :: Floating a => PlaneAngle a -> Homo33 DOne a
rotX a = consRow (vCons _1 $ vCons _0 $ vSing _0)
$ consRow (vCons _0 $ vCons (cos a) $ vSing (negate (sin a)))
$ rowMatrix (vCons _0 $ vCons (sin a) $ vSing (cos a))

rotY :: Floating a => PlaneAngle a -> Homo33 DOne a
rotY a = consRow (vCons (cos a) $ vCons _0 $ vSing (sin a))
$ consRow (vCons _0 $ vCons _1 $ vSing _0)
$ rowMatrix (vCons (negate (sin a)) $ vCons _0 $ vSing (cos a))

rotZ :: Floating a => PlaneAngle a -> Homo33 DOne a
rotZ a = consRow (vCons (cos a) $ vCons (negate (sin a)) $ vSing _0)
$ consRow (vCons (sin a) $ vCons (cos a) $ vSing _0)
$ rowMatrix (vCons _0 $ vCons _0 $ vSing _1)

0 comments on commit 04521bd

Please sign in to comment.