matrixutils.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2019 Google Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef CARDBOARD_SDK_UTIL_MATRIXUTILS_H_
  17. #define CARDBOARD_SDK_UTIL_MATRIXUTILS_H_
  18. //
  19. // This file contains operators and free functions that define generic Matrix
  20. // operations.
  21. //
  22. #include "matrix_3x3.h"
  23. #include "rotation.h"
  24. #include "vector.h"
  25. namespace cardboard {
  26. // Returns the transpose of a matrix.
  27. Matrix3x3 Transpose(const Matrix3x3& m);
  28. // Multiplies a Matrix and a column Vector of the same Dimension to produce
  29. // another column Vector.
  30. Vector3 operator*(const Matrix3x3& m, const Vector3& v);
  31. // Returns the determinant of the matrix. This function is defined for all the
  32. // typedef'ed Matrix types.
  33. double Determinant(const Matrix3x3& m);
  34. // Returns the adjugate of the matrix, which is defined as the transpose of the
  35. // cofactor matrix. This function is defined for all the typedef'ed Matrix
  36. // types. The determinant of the matrix is computed as a side effect, so it is
  37. // returned in the determinant parameter if it is not null.
  38. Matrix3x3 AdjugateWithDeterminant(const Matrix3x3& m, double* determinant);
  39. // Returns the inverse of the matrix. This function is defined for all the
  40. // typedef'ed Matrix types. The determinant of the matrix is computed as a
  41. // side effect, so it is returned in the determinant parameter if it is not
  42. // null. If the determinant is 0, the returned matrix has all zeroes.
  43. Matrix3x3 InverseWithDeterminant(const Matrix3x3& m, double* determinant);
  44. // Returns the inverse of the matrix. This function is defined for all the
  45. // typedef'ed Matrix types. If the determinant of the matrix is 0, the returned
  46. // matrix has all zeroes.
  47. Matrix3x3 Inverse(const Matrix3x3& m);
  48. // Returns a 3x3 Matrix representing a 3D rotation. This creates a Matrix that
  49. // does not work with homogeneous coordinates, so the function name ends in
  50. // "NH".
  51. Matrix3x3 RotationMatrixNH(const Rotation& r);
  52. } // namespace cardboard
  53. #endif // CARDBOARD_SDK_UTIL_MATRIXUTILS_H_