Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved 3D rotation matrices from ...Matrix.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |