diff --git a/fixed_wide_vectors/src/macros/matrix.rs b/fixed_wide_vectors/src/macros/matrix.rs index ecd0d85..da7f209 100644 --- a/fixed_wide_vectors/src/macros/matrix.rs +++ b/fixed_wide_vectors/src/macros/matrix.rs @@ -191,6 +191,32 @@ macro_rules! impl_matrix_named_fields { #[macro_export(local_inner_macros)] macro_rules! impl_matrix_3x3 { ()=>{ + impl Matrix<3,3,T> + where + //cross + T:core::ops::Mul+Copy, + T2:core::ops::Sub, + //dot + T:core::ops::Mul<::Output,Output=T3>, + T3:core::iter::Sum, + { + pub fn det(self)->T3{ + self.x_axis.dot(self.y_axis.cross(self.z_axis)) + } + } + impl Matrix<3,3,T> + where + T:core::ops::Mul+Copy, + T2:core::ops::Sub, + { + pub fn adjugate(self)->Matrix<3,3,::Output>{ + Matrix::new([ + [self.y_axis.y*self.z_axis.z-self.y_axis.z*self.z_axis.y,self.x_axis.z*self.z_axis.y-self.x_axis.y*self.z_axis.z,self.x_axis.y*self.y_axis.z-self.x_axis.z*self.y_axis.y], + [self.y_axis.z*self.z_axis.x-self.y_axis.x*self.z_axis.z,self.x_axis.x*self.z_axis.z-self.x_axis.z*self.z_axis.x,self.x_axis.z*self.y_axis.x-self.x_axis.x*self.y_axis.z], + [self.y_axis.x*self.z_axis.y-self.y_axis.y*self.z_axis.x,self.x_axis.y*self.z_axis.x-self.x_axis.x*self.z_axis.y,self.x_axis.x*self.y_axis.y-self.x_axis.y*self.y_axis.x], + ]) + } + } #[cfg(feature="fixed_wide")] $crate::impl_matrix_wide_3x3!(); } diff --git a/fixed_wide_vectors/src/tests/fixed_wide.rs b/fixed_wide_vectors/src/tests/fixed_wide.rs index 5701f8e..9b363bb 100644 --- a/fixed_wide_vectors/src/tests/fixed_wide.rs +++ b/fixed_wide_vectors/src/tests/fixed_wide.rs @@ -71,7 +71,7 @@ fn wide_matrix_det(){ ]); // In[2]:= Det[{{1, 2, 3}, {4, 5, 7}, {6, 8, 9}}] // Out[2]= 7 - assert_eq!(m.wide_det_3x3_1(),fixed_wide::fixed::Fixed::<3,96>::from(7)); + assert_eq!(m.det(),fixed_wide::fixed::Fixed::<3,96>::from(7)); } #[test] @@ -84,7 +84,7 @@ fn wide_matrix_adjugate(){ // In[6]:= Adjugate[{{1, 2, 3}, {4, 5, 7}, {6, 8, 9}}] // Out[6]= {{-11, 6, -1}, {6, -9, 5}, {2, 4, -3}} assert_eq!( - m.wide_adjugate_3x3_1().array, + m.adjugate().array, Matrix3::new([ [Planar64Wide1::from(-11),Planar64Wide1::from(6),Planar64Wide1::from(-1)], [Planar64Wide1::from(6),Planar64Wide1::from(-9),Planar64Wide1::from(5)],