本文整理汇总了C++中polygon::get方法的典型用法代码示例。如果您正苦于以下问题:C++ polygon::get方法的具体用法?C++ polygon::get怎么用?C++ polygon::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polygon
的用法示例。
在下文中一共展示了polygon::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lineIntersectsPolygon
result lineIntersectsPolygon(line & l, polygon & P, size_t sz, int k) {
int n = (sz + k - 1) / k;
double minDist = numeric_limits<double>::max();
int minPoint = -1;
unordered_set<int> points;
if (n <= 50) {
point prev = P->get(0);
for (size_t i = k; i < sz; i += k) {
point cur = P->get(i);
segment s = {prev, cur};
if (lineIntersectsSegment(l, s)) {
points.insert(i - k);
} else {
double dist = fabs(l.dist(cur));
if (minDist > dist) {
minDist = dist;
minPoint = i;
}
}
prev = cur;
}
} else {
auto ind = lineIntersectsPolygon(l, P, sz, 2 * k);
if (ind.points.size() != 0) {
for (int i : ind.points) {
point p1 = P->get(i - k);
point p2 = P->get(i);
segment s = {p1, p2};
if (lineIntersectsSegment(l, s)) {
points.insert((i - k + sz) % sz);
} else {
points.insert(i);
}
}
} else {
int i = ind.closest;
point p1 = P->get(i - 2 * k);
point p2 = P->get(i - k);
point p3 = P->get(i);
point p4 = P->get(i + k);
point p5 = P->get(i + 2 * k);
point pts[] = {p1, p2, p3, p4, p5};
segment segs[] = {{p1, p2}, {p2, p3}, {p3, p4}, {p4, p5}};
for (int j = 0; j < 4; j++) {
if (lineIntersectsSegment(l, segs[j])) {
points.insert((i + k * (j - 2) + sz) % sz);
}
}
for (int j = 0; j < 5; j++) {
double dist = fabs(l.dist(pts[j]));
if (minDist > dist) {
minDist = dist;
minPoint = (i + k * (j - 2) + sz) % sz;
}
}
}
}
return {points, minPoint};
}
示例2: toCGALPolygon
CGALPolygon toCGALPolygon(polygon p) {
vector<CGALPoint> pnts;
for (auto v : p.get()) pnts.push_back(CGALPoint(v[0], v[1]));
return CGALPolygon( &pnts[0], &pnts[pnts.size()-1] );
}