package geom // Matrix3x3F32 is an matrix with 3 vectors, i, j and k (floating point, 32 bits). type Matrix3x3F32 struct { I Vector3F32 J Vector3F32 K Vector3F32 } // Mx3x3F32 is a shorthand function to create a matrix. func Mx3x3F32(i, j, k Vector3F32) Matrix3x3F32 { return Matrix3x3F32{i, j, k} } // Adj calculates the adjugate matrix of matrix m. func (m Matrix3x3F32) Adj() Matrix3x3F32 { return Mx3x3F32( Vec3F32(m.J.Y*m.K.Z-m.K.Y*m.J.Z, m.K.Y*m.I.Z-m.I.Y*m.K.Z, m.I.Y*m.J.Z-m.J.Y*m.I.Z), Vec3F32(m.K.X*m.J.Z-m.J.X*m.K.Z, m.I.X*m.K.Z-m.K.X*m.I.Z, m.J.X*m.I.Z-m.I.X*m.J.Z), Vec3F32(m.J.X*m.K.Y-m.K.X*m.J.Y, m.K.X*m.I.Y-m.I.X*m.K.Y, m.I.X*m.J.Y-m.J.X*m.I.Y), ) } // Det calculates the determinant of the matrix m. func (m Matrix3x3F32) Det() float32 { return m.I.X*m.J.Y*m.K.Z + m.J.X*m.K.Y*m.I.Z + m.K.X*m.I.Y*m.J.Z - m.K.X*m.J.Y*m.I.Z - m.J.X*m.I.Y*m.K.Z - m.I.X*m.K.Y*m.J.Z } // MulMx multiplies the matrix m with matrix n. func (m Matrix3x3F32) MulMx(n Matrix3x3F32) Matrix3x3F32 { return Matrix3x3F32{ Vec3F32( n.I.X*m.I.X+n.I.Y*m.J.X+n.I.Z*m.K.X, n.I.X*m.I.Y+n.I.Y*m.J.Y+n.I.Z*m.K.Y, n.I.X*m.I.Z+n.I.Y*m.J.Z+n.I.Z*m.K.Z), Vec3F32( n.J.X*m.I.X+n.J.Y*m.J.X+n.J.Z*m.K.X, n.J.X*m.I.Y+n.J.Y*m.J.Y+n.J.Z*m.K.Y, n.J.X*m.I.Z+n.J.Y*m.J.Z+n.J.Z*m.K.Z), Vec3F32( n.K.X*m.I.X+n.K.Y*m.J.X+n.K.Z*m.K.X, n.K.X*m.I.Y+n.K.Y*m.J.Y+n.K.Z*m.K.Y, n.K.X*m.I.Z+n.K.Y*m.J.Z+n.K.Z*m.K.Z), } } // MulVec multiplies the matrix m with vector v. func (m Matrix3x3F32) MulVec(v Vector3F32) Vector3F32 { return Vec3F32( v.X*m.I.X+v.Y*m.J.X+v.Z*m.K.X, v.X*m.I.Y+v.Y*m.J.Y+v.Z*m.K.Y, v.X*m.I.Z+v.Y*m.J.Z+v.Z*m.K.Z) } // ScaleVec scales the matrix m by vector v. func (m Matrix3x3F32) ScaleVec(v Vector3F32) Matrix3x3F32 { return Matrix3x3F32{ Vec3F32(v.X*m.I.X, v.X*m.I.Y, v.X*m.I.Z), Vec3F32(v.Y*m.I.X, v.Y*m.I.Y, v.Y*m.I.Z), Vec3F32(v.Z*m.I.X, v.Z*m.I.Y, v.Z*m.I.Z), } }