![](/img/trans.png)
[英]Calculate intersection point between line and polygon with Boost.Geometry
[英]Boost.Geometry polygon point assignment
我正在嘗試使用Boost幾何,並且難以將點分配給多邊形。 假設我創建一個點的靜態向量
boost::geometry::model::d2::point_xy<double> >* a;
然后我創建一個多邊形:
boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;
假設我已經定義了a點的值。
如何將點從a分配到P?
boost::geometry::assign_points()
算法可用於為多邊形分配點范圍。
如果a
是點的范圍,而P
是多邊形,則將使用:
boost::geometry::assign_points(P, a);
這是一個完整的示例,演示了assign_points
的用法:
#include <iostream>
#include <vector>
#include <boost/assign/std/vector.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/area.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/io/dsv/write.hpp>
int main()
{
using namespace boost::assign;
typedef boost::geometry::model::d2::point_xy<double> point_xy;
// Create points to represent a 5x5 closed polygon.
std::vector<point_xy> points;
points +=
point_xy(0,0),
point_xy(0,5),
point_xy(5,5),
point_xy(5,0),
point_xy(0,0)
;
// Create a polygon object and assign the points to it.
boost::geometry::model::polygon<point_xy> polygon;
boost::geometry::assign_points(polygon, points);
std::cout << "Polygon " << boost::geometry::dsv(polygon) <<
" has an area of " << boost::geometry::area(polygon) << std::endl;
}
產生以下輸出:
Polygon (((0, 0), (0, 5), (5, 5), (5, 0), (0, 0))) has an area of 25
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.