Skip to content

Commit

Permalink
ENH: Add overloaded fct for CosBetweenVectors fct (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarquisbq committed Apr 14, 2023
1 parent 44b7bca commit c0e89fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Source/SIMPLib/Math/GeometryMath.cpp
Expand Up @@ -66,6 +66,19 @@ double GeometryMath::CosThetaBetweenVectors(const double a[3], const double b[3]
}
return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) / (norm1 * norm2);
}
float GeometryMath::CosThetaBetweenVectors(const Eigen::Vector3f& vectorA, const Eigen::Vector3f& vectorB)
{
const float normA = vectorA.norm();
const float normB = vectorB.norm();

if(normA == 0.0f || normB == 0.0f)
{
return 1.0f;
}

return vectorA.dot(vectorB) / (normA * normB);
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions Source/SIMPLib/Math/GeometryMath.h
Expand Up @@ -37,6 +37,8 @@

#include <memory>

#include <Eigen/Dense>

#include "SIMPLib/SIMPLib.h"
#include "SIMPLib/DataArrays/DynamicListArray.hpp"

Expand All @@ -62,6 +64,7 @@ namespace GeometryMath
*/
SIMPLib_EXPORT float CosThetaBetweenVectors(const float a[3], const float b[3]);
SIMPLib_EXPORT double CosThetaBetweenVectors(const double a[3], const double b[3]);
SIMPLib_EXPORT float CosThetaBetweenVectors(const Eigen::Vector3f& vectorA, const Eigen::Vector3f& vectorB);

/**
* @brief Computes the angle in RADIANS between 2 vectors.
Expand Down

0 comments on commit c0e89fa

Please sign in to comment.