Skip to content
Snippets Groups Projects
Commit 584eded4 authored by Timo Koch's avatar Timo Koch
Browse files

Merge branch 'feature/embedded-circlep-separate-helper' into 'master'

[md][embedded] Factor out sin/cos precomputation

See merge request !2536
parents b05a5b67 a3e994d6
No related branches found
No related tags found
1 merge request!2536[md][embedded] Factor out sin/cos precomputation
...@@ -82,21 +82,12 @@ void circlePoints(std::vector<GlobalPosition>& points, ...@@ -82,21 +82,12 @@ void circlePoints(std::vector<GlobalPosition>& points,
/*! /*!
* \ingroup EmbeddedCoupling * \ingroup EmbeddedCoupling
* \brief returns a vector of points on a circle * \brief returns a vector of sin and cos values of a circle parametrization
* \param center the circle center
* \param normal the normal to the circle plane
* \param radius the circle radius
* \param numPoints the number of points * \param numPoints the number of points
*/ */
template<class GlobalPosition, class Scalar> template<class Scalar = double>
std::vector<GlobalPosition> circlePoints(const GlobalPosition& center, std::vector<Scalar> circlePointsSinCos(const std::size_t numPoints)
const GlobalPosition& normal,
const Scalar radius,
const std::size_t numPoints = 20)
{ {
std::vector<GlobalPosition> points;
// precompute the sin/cos
std::vector<Scalar> sincos(2*numPoints); std::vector<Scalar> sincos(2*numPoints);
Scalar t = 0 + 0.1; // add arbitrary offset Scalar t = 0 + 0.1; // add arbitrary offset
for (std::size_t i = 0; i < numPoints; ++i) for (std::size_t i = 0; i < numPoints; ++i)
...@@ -107,7 +98,27 @@ std::vector<GlobalPosition> circlePoints(const GlobalPosition& center, ...@@ -107,7 +98,27 @@ std::vector<GlobalPosition> circlePoints(const GlobalPosition& center,
t += 2*M_PI/numPoints; t += 2*M_PI/numPoints;
if(t > 2*M_PI) t -= 2*M_PI; if(t > 2*M_PI) t -= 2*M_PI;
} }
return sincos;
}
/*!
* \ingroup EmbeddedCoupling
* \brief returns a vector of points on a circle
* \param center the circle center
* \param normal the normal to the circle plane
* \param radius the circle radius
* \param numPoints the number of points
*/
template<class GlobalPosition, class Scalar>
std::vector<GlobalPosition> circlePoints(const GlobalPosition& center,
const GlobalPosition& normal,
const Scalar radius,
const std::size_t numPoints = 20)
{
// precompute the sin/cos values
const auto sincos = circlePointsSinCos<Scalar>(numPoints);
std::vector<GlobalPosition> points;
circlePoints(points, sincos, center, normal, radius); circlePoints(points, sincos, center, normal, radius);
return points; return points;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment