{-# LANGUAGE FunctionalDependencies
, FlexibleInstances #-}
module LieExample.SO3 ( Vector (..)
, crossProduct
) where
import Lie.LieAlgebra
data Vector = V Double Double Double
deriving Eq
crossProduct :: Vector -> Vector -> Vector
crossProduct (V a b c) (V d e f) = V (b * f - c * e)
(c * d - a * f)
(a * e - b * d)
instance Show Vector where
show (V a b c) = "(" ++ show a
++ " " ++ show b
++ " " ++ show c
++ ")"
instance LieAlgebra Vector Double where
(|+|) (V a b c) (V d e f) = V (a + b)
(c + d)
(e + f)
(|*|) alpha (V a b c) = V (alpha * a)
(alpha * b)
(alpha * c)
(|.|) = crossProduct
basis = [ V 1 0 0
, V 0 1 0
, V 0 0 1
]
trace f = sum $ zipWith euclideanScalarproduct transformedBasis basis
where transformedBasis = map f basis
euclideanScalarproduct :: Vector -> Vector -> Double
euclideanScalarproduct (V a b c) (V d e f) = a * d + b * e + c * f