Skip to content

Commit c0e89fa

Browse files
authored
ENH: Add overloaded fct for CosBetweenVectors fct (#437)
1 parent 44b7bca commit c0e89fa

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Source/SIMPLib/Math/GeometryMath.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ double GeometryMath::CosThetaBetweenVectors(const double a[3], const double b[3]
6666
}
6767
return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) / (norm1 * norm2);
6868
}
69+
float GeometryMath::CosThetaBetweenVectors(const Eigen::Vector3f& vectorA, const Eigen::Vector3f& vectorB)
70+
{
71+
const float normA = vectorA.norm();
72+
const float normB = vectorB.norm();
73+
74+
if(normA == 0.0f || normB == 0.0f)
75+
{
76+
return 1.0f;
77+
}
78+
79+
return vectorA.dot(vectorB) / (normA * normB);
80+
}
81+
6982
// -----------------------------------------------------------------------------
7083
//
7184
// -----------------------------------------------------------------------------

Source/SIMPLib/Math/GeometryMath.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
#include <memory>
3939

40+
#include <Eigen/Dense>
41+
4042
#include "SIMPLib/SIMPLib.h"
4143
#include "SIMPLib/DataArrays/DynamicListArray.hpp"
4244

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

6669
/**
6770
* @brief Computes the angle in RADIANS between 2 vectors.

0 commit comments

Comments
 (0)