반응형
boost::geometry::within
- 입력한 두 geometry의 포함 여부를 계산하는 함수
- geometry1이 geometry2에 포함되는지 검사
- return boolean
template<typename Geometry1, typename Geometry2>
bool within(Geometry1 const & geometry1, Geometry2 const & geometry2)
point_t point1;
boost::geometry::model::polygon poly1;
const auto& _isWithIn = boost::geometry::within(point1, poly1);
----> ok
const auto& _isWithIn = boost::geometry::within(poly1, point1);
----> fail
boost::geometry::intersects
- 입력한 두 geometry의 충돌 여부를 계산하는 함수
- geometry1이 geometry2와 충돌하는지 검사
- return boolean
template<typename Geometry1, typename Geometry2>
bool intersects(Geometry1 const & geometry1, Geometry2 const & geometry2)
boost::geometry::model::polygon poly1, poly2;
const auto& hasIntersects = boost::geometry::intersects(poly1, poly2);
728x90
boost::geometry::intersection
- 입력된 두 geometry 간 교집합을 계산하는 함수
template<typename Geometry1, typename Geometry2, typename GeometryOut>
bool intersection(Geometry1 const & geometry1, Geometry2 const & geometry2, GeometryOut & geometry_out)
void draw_intersection()
{
boost::geometry::model::polygon green, blue;
boost::geometry::read_wkt(
"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green);
boost::geometry::read_wkt(
"POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue);
boost::geometry::correct(green);
boost::geometry::correct(blue);
boost::geometry::model::multi_polygon output;
boost::geometry::intersection(green, blue, output);
int i = 0;
std::cout << "green && blue:" << std::endl;
std::ofstream svg("draw_intersection.svg");
boost::geometry::svg_mapper<point_t> mapper(svg, 1024, 1024);
mapper.add(green);
mapper.map(green, "fill-opacity:0.5;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1", 2);
mapper.add(blue);
mapper.map(blue, "fill-opacity:0.5;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1", 2);
mapper.add(output);
mapper.map(output, "fill-opacity:1.0;fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1", 2);
}
boost::geometry::difference
- 입력된 두 geometry 간 차집합을 계산하는 함수
template<typename Geometry1, typename Geometry2, typename Collection>
void difference(Geometry1 const & geometry1, Geometry2 const & geometry2, Collection & output_collection)
boost::geometry::model::polygon green, blue;
boost::geometry::read_wkt(
"POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
"(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", green);
boost::geometry::read_wkt(
"POLYGON((4.0 -0.5 , 3.5 1.0 , 2.0 1.5 , 3.5 2.0 , 4.0 3.5 , 4.5 2.0 , 6.0 1.5 , 4.5 1.0 , 4.0 -0.5))", blue);
boost::geometry::correct(green);
boost::geometry::correct(blue);
boost::geometry::model::multi_polygon output;
boost::geometry::difference(green, blue, output);
int i = 0;
std::cout << "green && blue:" << std::endl;
std::ofstream svg("draw_difference.svg");
boost::geometry::svg_mapper<point_t> mapper(svg, 1024, 1024);
mapper.add(green);
mapper.map(green, "fill-opacity:0.5;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1", 2);
mapper.add(blue);
mapper.map(blue, "fill-opacity:0.5;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1", 2);
mapper.add(output);
mapper.map(output, "fill-opacity:1.0;fill:rgb(255,0,0);stroke:rgb(0,0,0);stroke-width:1", 2);
반응형
'개발 > C++' 카테고리의 다른 글
C++ 람다 함수 정리 (1) | 2023.01.25 |
---|---|
C++20 신규 기능 정리 (0) | 2023.01.25 |
std::unordered_map 정렬하기 (0) | 2022.10.06 |
[Boost Geometry] points -> polygon cluster (0) | 2022.08.10 |
std::string tokenizing 방법 (0) | 2022.04.19 |