#define Flt Float
#define VECT_Float
module Data.Vect.Flt.Util.Dim4 where
import Data.Vect.Flt.Base
import Data.Vect.Flt.GramSchmidt
structVec4 :: [Flt] -> [Vec4]
structVec4 [] = []
structVec4 (x:y:z:w:ls) = (Vec4 x y z w):(structVec4 ls)
structVec4 _ = error "structVec4"
destructVec4 :: [Vec4] -> [Flt]
destructVec4 [] = []
destructVec4 ((Vec4 x y z w):ls) = x:y:z:w:(destructVec4 ls)
translate4X :: Flt -> Vec4 -> Vec4
translate4Y :: Flt -> Vec4 -> Vec4
translate4Z :: Flt -> Vec4 -> Vec4
translate4W :: Flt -> Vec4 -> Vec4
translate4X t (Vec4 x y z w) = Vec4 (x+t) y z w
translate4Y t (Vec4 x y z w) = Vec4 x (y+t) z w
translate4Z t (Vec4 x y z w) = Vec4 x y (z+t) w
translate4W t (Vec4 x y z w) = Vec4 x y z (w+t)
vec4X :: Vec4
vec4Y :: Vec4
vec4Z :: Vec4
vec4W :: Vec4
vec4X = Vec4 1 0 0 0
vec4Y = Vec4 0 1 0 0
vec4Z = Vec4 0 0 1 0
vec4W = Vec4 0 0 0 1
biVector4 :: Vec4 -> Vec4 -> (Flt,Flt,Flt,Flt,Flt,Flt)
biVector4 (Vec4 x y z w) (Vec4 a b c d) =
( x*by*a , x*cz*a , x*dw*a , y*cz*b , y*d+w*b , z*dw*c )
biVector4AsTensor :: Vec4 -> Vec4 -> Mat4
biVector4AsTensor v w =
Mat4 ( Vec4 0 ( r) ( q) ( p) )
( Vec4 (r) 0 ( z) (y) )
( Vec4 (q) (z) 0 ( x) )
( Vec4 (p) ( y) (x) 0 )
where
(x,y,z,p,q,r) = biVector4 v w
rotate4' :: Flt -> (Normal4,Normal4) -> Vec4 -> Vec4
rotate4' angle axes v = v .* (rotMatrix4' angle axes)
rotate4 :: Flt -> (Vec4,Vec4) -> Vec4 -> Vec4
rotate4 angle axes v = v .* (rotMatrix4 angle axes)
rotMatrix4' :: Flt -> (Normal4,Normal4) -> Mat4
rotMatrix4' angle (u1,u2) = m1 &+ (s *& m2) &+ m3
where
v = fromNormal u1 ; w = fromNormal u2
c = cos angle ; s = sin angle
m1 = scalarMul (1c) ( outer v v &+ outer w w )
m2 = biVector4AsTensor v w
m3 = diag (Vec4 c c c c)
rotMatrix4 :: Flt -> (Vec4,Vec4) -> Mat4
rotMatrix4 angle axes =
rotMatrix4' angle $ liftPair toNormalUnsafe $ gramSchmidtNormalize axes
where
liftPair f (x,y) = (f x, f y)