Im playing around with the new geometry library made available in boost 1.47 and wanted to know if it is possible to define a 2D polar system.
In the header files and documentation I found a definition for a polar system but when trying to use it with the sample code below I’m getting compilation errors:
using namespace boost;
typedef geometry::cs::polar<geometry::radian> geometry_type;
typedef geometry::model::point<double, 2, geometry_type> point_type;
const double PI = math::constants::pi<double>();
point_type p1(0, 0);
point_type p2(1, PI/2);
double dist = geometry::distance(p1, p2); // COMPILATION FAILS HERE
in VC2010 I get: “error C2039: ‘type’ : is not a member of ‘boost::geometry::traits::cs_tag'” when trying to compile the distance function above.
This is the definition for the polar system extracted from the boost header files (boost/geometry/core/cs.hpp):
/*!
\brief Polar coordinate system
\details Defines the polar coordinate system "in which each point
on a plane is determined by an angle and a distance"
\see http://en.wikipedia.org/wiki/Polar_coordinates
\ingroup cs
*/
template<typename DegreeOrRadian>
struct polar
{
typedef DegreeOrRadian units;
};
But I think that the definition is incomplete since “polar” is not mentioned anywhere else. Am I supposed to define a distance strategy and other needed traits all by myself for a simple 2D polar system?
Well, answering my own question (hope that this is ok) after a bit more of research: It seems that I got the wrong idea about coordinate systems in the geometry library’s sense. The different coordinate systems seem to specify the intrinsic geometry like the surface of a sphere where for example the distance between two points are not computed in a cartesian way.
What I wanted to accomplish (use a polar system) can be done by defining a new point class that takes the polar coordinates and converts them to X and Y coordinates. After registering the new point class with the BOOST_GEOMETRY_REGISTER_POINT_2D macro (like in the boost samples) and using a normal cartesian system all geometry algorithms work as expected.