Commit 7f4c4e6b authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/circle-get-point' into 'master'

Feature/circle get point

See merge request DennisGlaeser/frackit!37
parents b664a7b1 2835d477
......@@ -109,6 +109,45 @@ public:
bool contains(const Point& p) const
{ return contains(p, Precision<ctype>::confusion()*radius()); }
/*!
* \brief Returns the point on the circle for the given parameter
* \param param The parameter (0.0 <= param <= 1.0)
* \note param = 0.0 corresponds to the point on the circle
* for an angle of 0 w.r.t. the circle-local coordinate
* system consisting of base1() and base2().
* Similarly, param = 1.0 corresponds to 2*Pi.
*/
Point getPoint(ctype param) const
{
assert(param >= 0.0 && param <= 1.0);
return getPointFromAngle(2.0*M_PI*param);
}
/*!
* \brief Returns the point on the circle for a given angle
* \param angle The angle in radians
* \note The angle is to be understood with respect to the
* circle-local coordinate system consisting of base1()
* and base2().
*/
Point getPointFromAngle(ctype angle) const
{
assert(!std::signbit(angle));
using std::sin;
using std::cos;
const auto x = cos(angle)*this->radius();
const auto y = sin(angle)*this->radius();
auto xVec = Vector(this->base1()); xVec *= x;
auto yVec = Vector(this->base2()); yVec *= y;
auto result = this->center();
result += xVec;
result += yVec;
return result;
}
private:
//! constructs the base geometry
ParentType makeBaseGeometry_(const Point& center,
......
......@@ -2,6 +2,7 @@
#include <string>
#include <frackit/geometry/circle.hh>
#include <frackit/precision/precision.hh>
//! test some functionality of circles
int main()
......@@ -32,6 +33,12 @@ int main()
if (!circle.contains(Point(1.0, 0.0, 0.0)))
throw std::runtime_error("False negative contains() result");
// start and end point should be the same
const auto p1 = circle.getPoint(0.0);
const auto p2 = circle.getPoint(1.0);
if (!p1.isEqual(p2, Frackit::Precision<ctype>::confusion()))
throw std::runtime_error("Start and end point not equal");
std::cout << "All tests passed" << std::endl;
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment