简体   繁体   English

Boost Geometry:使用二维极坐标系

[英]Boost Geometry: using a 2D polar coordinate system

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.我在玩 boost 1.47 中提供的新几何库,想知道是否可以定义 2D 极坐标系统。 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:在 header 文件和文档中,我找到了极坐标系统的定义,但是当尝试将其与下面的示例代码一起使用时,我遇到了编译错误:

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.在 VC2010 中,我得到:“错误 C2039:'type': is not a member of 'boost::geometry::traits::cs_tag'”尝试编译上述距离 function 时。

This is the definition for the polar system extracted from the boost header files (boost/geometry/core/cs.hpp):这是从 boost header 文件 (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?我是否应该为一个简单的 2D 极坐标系统自己定义一个距离策略和其他需要的特征?

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.我想要完成的(使用极坐标系统)可以通过定义一个新点 class 来完成,该点采用极坐标并将它们转换为 X 和 Y 坐标。 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.在使用 BOOST_GEOMETRY_REGISTER_POINT_2D 宏注册新点 class (如在 boost 示例中)并使用普通笛卡尔系统后,所有几何算法都按预期工作。

The trouble with type traits is you have to write your own specialisation for each client type.类型特征的问题是您必须为每种客户端类型编写自己的专业化。

(This is not true of the standard <traits> library in C++0x.) (这不适用于 C++0x 中的标准<traits>库。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM