3
0

Utilities.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. namespace NumericalMethods
  10. {
  11. class VectorVariable;
  12. namespace Eigenanalysis
  13. {
  14. //! Compute the cross product between two 3D vectors.
  15. //! @param lhs The left-hand side vector.
  16. //! @param rhs The right-hand side vector.
  17. //! @return The 3D vector equal to the cross product if both input vectors are 3-dimensional.
  18. VectorVariable CrossProduct(const VectorVariable& lhs, const VectorVariable& rhs);
  19. //! Robustly computes a right-handed orthonormal basis containing a given unit-length 3D input vector.
  20. //! @param vecW[in] A 3D input vector which must be of unit length.
  21. //! @param vecU[out] The first of the computed unit-length orthogonal vectors.
  22. //! @param vecV[out] The second of the computed unit-length orthogonal vectors.
  23. //! @return {vecU, vecV, vecW} will be a right-handed orthogonal set.
  24. void ComputeOrthogonalComplement(const VectorVariable& vecW, VectorVariable& vecU, VectorVariable& vecV);
  25. //! Given elements of a symmetric 3x3 matrix and one of its eigenvalues, computes the corresponding eigenvector.
  26. //! For numerical stability, this function should only be used to find the eigenvector corresponding to
  27. //! eigenvalues that are unique and numerically not close to other eigenvalues.
  28. //! @param a<ij> The element of the matrix in row i, column j.
  29. //! @param val One of the eigenvalues of the matrix.
  30. //! @return The corresponding eigenvector.
  31. VectorVariable ComputeEigenvector0(
  32. double a00, double a01, double a02, double a11, double a12, double a22, double val
  33. );
  34. //! Given elements of a symmetric 3x3 matrix, one of its eigenvalues and an unrelated eigenvector, computes the
  35. //! eigenvector corresponding to the eigenvalue.
  36. //! This algorithm is numerically stable even if the eigenvalue is repeated.
  37. //! @param a<ij> The element of the matrix in row i, column j.
  38. //! @param val The eigenvalue whose corresponding eigenvector is to be found.
  39. //! @param vec The unrelated eigenvector that is already known.
  40. //! @return The eigenvector corresponding to the given eigenvalue.
  41. VectorVariable ComputeEigenvector1(
  42. double a00,
  43. double a01,
  44. double a02,
  45. double a11,
  46. double a12,
  47. double a22,
  48. double val,
  49. const VectorVariable& vec
  50. );
  51. // Given two eigenvectors of a symmetric 3x3 matrix, computes the third.
  52. // The third eigenvector is found by taking the cross product of the known eigenvectors (the eigenvectors of a
  53. // real symmetric 3x3 matrix are always orthogonal).
  54. //! @param vec0 The first of the already known eigenvectors.
  55. //! @param vec1 The second of the already known eigenvectors.
  56. //! @return The computed eigenvector.
  57. VectorVariable ComputeEigenvector2(const VectorVariable& vec0, const VectorVariable& vec1);
  58. } // namespace Eigenanalysis
  59. } // namespace NumericalMethods