Estimates the parameters of a circle from a set of 2D points lying on the circle. More...
#include <FitCircle.hpp>
Inheritance diagram for TRTK::FitCircle< T >:
Collaboration diagram for TRTK::FitCircle< T >:Public Types | |
| typedef super::Vector2T | Vector2T |
| 2D column vector with value type T. | |
| typedef super::Vector3T | Vector3T |
| 3D column vector with value type T. | |
| typedef super::VectorXT | VectorXT |
| Column vector of arbitrary size with value type T. | |
| typedef super::MatrixXT | MatrixXT |
| Matrix of arbitrary size with value type T. | |
| typedef super::Matrix2T | Matrix2T |
| 2 x 2 matrix with value type T. | |
| enum | Error { DATA_POINTS_TOO_SIMILAR, INFINITY_NOT_AVAILABLE, NAN_NOT_AVAILABLE, NOT_ENOUGH_POINTS, UNKNOWN_ERROR, WRONG_POINT_SIZE } |
|
typedef Eigen::Array< T, Eigen::Dynamic, 1 > | ArrayXT |
| General-purpose array of arbitrary size with value type T. | |
| typedef Eigen::Matrix< T, 4, 1 > | Vector4T |
| 4D column vector with value type T. | |
| typedef Eigen::Matrix< T, 3, 3 > | Matrix3T |
| 3 x 3 matrix with value type T. | |
Public Member Functions | |
| FitCircle () | |
| Constructs an empty FitCircle object. | |
| FitCircle (const std::vector< Coordinate< T > > &points) | |
| Constructs a FitCircle object. | |
| FitCircle (const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &points) | |
| Constructs a FitCircle object. | |
| FitCircle (const std::vector< Vector3T > &points) | |
| Constructs a FitCircle object. | |
| virtual | ~FitCircle () |
| Destructs the FitCircle object. | |
| void | compute () |
| Estimates the parameters of the circle. | |
| unsigned | getNumberPointsRequired () const |
| Returns the minimum number of data points required to compute a model. | |
| const Coordinate< T > & | getCenterPoint () const |
| Returns the center point of the plane. | |
| T | getDistanceTo (const Coordinate< T > &point) const |
| Returns the shortest distance from the circle to the given point. | |
| T | getRadius () const |
| Returns the radius of the circle. | |
| T | getRMS () const |
| Returns the root mean square error. | |
| void | setPoints (const std::vector< Coordinate< T > > &) |
| Sets the point set. | |
| void | setPoints (const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &) |
| Sets the point set. | |
| void | setPoints (const std::vector< Vector3T > &) |
| Sets the point set. | |
Public Attributes | |
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef T | value_type |
| Internally used value type (should be a floating point type). | |
Protected Attributes | |
| MatrixXT | m_points |
Estimates the parameters of a circle from a set of 2D points lying on the circle.
| T | scalar type of the coordinates |
This class allows estimating the center point and the radius of a circle from known points on the circle. The points may be erroneous since a least square fitting is done. If \( (x_i, y_i)^T \) are the data points, \( (x_0, y_0)^T \) the center point, and \( r \) the radius, then FitCircle tries to minimize the sum of the squared residuals as shown below:
\[ (x_0, y_0, r) := \arg\min_{(x_0, y_0, r)} \sum_{i=1}^N \left[(x_i - x_0)^2 + (y_i - y_0)^2 - r^2 \right]^2 \]
Here is a more elaborate example to see how to use the class:
#include <cstdlib> #include <iostream> #include <TRTK/FitCircle.hpp> #include <TRTK/Tools.hpp> using namespace TRTK; int main() { double pi = 3.1415926535; std::vector<Coordinate<double> > circlePoints; // Construct some points lying on a circle. double radius = 7; Coordinate<double> centerPoint = Coordinate<double>(4, 2); for (double phi = 0.0; phi < 2.0 * pi; phi += pi/10) { using std::sin; using std::cos; using Tools::randn; double x = radius * cos(phi) + randn(0.0, 0.1); double y = radius * sin(phi) + randn(0.0, 0.1); Coordinate<double> point = centerPoint + Coordinate<double>(x, y); circlePoints.push_back(point); } // Estimate the circle parameters. FitCircle<double> fitCircle(circlePoints); fitCircle.compute(); std::cout << "Center point: " << fitCircle.getCenterPoint() << std::endl; std::cout << "Radius: " << fitCircle.getRadius() << std::endl; return 0; }
Output:
Center point: (4.03589, 1.97525) Radius: 7.03509
Definition at line 118 of file FitCircle.hpp.
enum TRTK::Fit::Error [inherited] |
| TRTK::FitCircle< T >::FitCircle | ( | ) |
Constructs an empty FitCircle object.
| T | scalar type of the coordinates |
Definition at line 164 of file FitCircle.hpp.
| TRTK::FitCircle< T >::FitCircle | ( | const std::vector< Coordinate< T > > & | points ) |
Constructs a FitCircle object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the circle. The points can be 2D or 3D homogeneous coordinates. |
Definition at line 180 of file FitCircle.hpp.
| TRTK::FitCircle< T >::FitCircle | ( | const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > & | points ) |
Constructs a FitCircle object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the circle. |
Definition at line 196 of file FitCircle.hpp.
| TRTK::FitCircle< T >::FitCircle | ( | const std::vector< Vector3T > & | points ) |
Constructs a FitCircle object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the circle. The points are assumed to be homogeneous coordinates, whose third coordinate entry is equal to one. |
Definition at line 214 of file FitCircle.hpp.
| TRTK::FitCircle< T >::~FitCircle | ( | ) | [virtual] |
Destructs the FitCircle object.
| T | scalar type of the coordinates |
Definition at line 228 of file FitCircle.hpp.
| void TRTK::FitCircle< T >::compute | ( | ) | [virtual] |
Estimates the parameters of the circle.
| T | scalar type of the coordinates |
There must be at least 3 points to perform the fitting.
| ErrorObj | If there are not enough points to fit the circle, an error object is thrown and its error code is set to WRONG_POINT_SIZE. |
Implements TRTK::Fit2D< T >.
Definition at line 247 of file FitCircle.hpp.
| const Coordinate< T > & TRTK::FitCircle< T >::getCenterPoint | ( | ) | const |
Returns the center point of the plane.
| T | scalar type of the coordinates |
Definition at line 350 of file FitCircle.hpp.
| T TRTK::FitCircle< T >::getDistanceTo | ( | const Coordinate< T > & | point ) | const [virtual] |
Returns the shortest distance from the circle to the given point.
| T | scalar type of the coordinates |
| [in] | point | A 2D coordinate. |
Implements TRTK::Fit2D< T >.
Definition at line 364 of file FitCircle.hpp.
| T TRTK::FitCircle< T >::getRadius | ( | ) | const |
Returns the radius of the circle.
| T | scalar type of the coordinates |
Definition at line 414 of file FitCircle.hpp.
| T TRTK::FitCircle< T >::getRMS | ( | ) | const [virtual] |
Returns the root mean square error.
| T | scalar type of the coordinates |
Implements TRTK::Fit2D< T >.
Definition at line 386 of file FitCircle.hpp.
| void TRTK::Fit2D< T >::setPoints | ( | const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > & | points ) | [inherited] |
| void TRTK::Fit2D< T >::setPoints | ( | const std::vector< Coordinate< T > > & | points ) | [virtual, inherited] |
Sets the point set.
| T | scalar type of the coordinates |
| [in] | points | The points can either be plain 2D or 3D homogeneous coordinates. |
| ErrorObj | If there are any coordinates other than 2D or 3D coordinates, an error object is thrown and its error code is set to WRONG_POINT_SIZE. |
Implements TRTK::Fit< T >.
| void TRTK::Fit2D< T >::setPoints | ( | const std::vector< Vector3T > & | points ) | [inherited] |
Sets the point set.
| T | scalar type of the coordinates |
| [in] | points | 3D homogeneous coordinates. |
Documentation generated by Doxygen