本文整理汇总了C++中polygon::size方法的典型用法代码示例。如果您正苦于以下问题:C++ polygon::size方法的具体用法?C++ polygon::size怎么用?C++ polygon::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polygon
的用法示例。
在下文中一共展示了polygon::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convex_intersect
polygon convex_intersect(const polygon &P, const polygon &Q) {
const int n = P.size(), m = Q.size();
int a = 0, b = 0, aa = 0, ba = 0;
enum { Pin, Qin, Unknown } in = Unknown;
polygon R;
do {
int a1 = (a+n-1) % n, b1 = (b+m-1) % m;
number C = cross(P[a] - P[a1], Q[b] - Q[b1]);
number A = cross(P[a1] - Q[b], P[a] - Q[b]);
number B = cross(Q[b1] - P[a], Q[b] - P[a]);
point r;
if (intersect_1pt(P[a1], P[a], Q[b1], Q[b], r)) {
if (in == Unknown) aa = ba = 0;
R.push_back( r );
in = B > number(0) ? Pin : A > number(0) ? Qin : in;
}
if (C == number(0) && B == number(0) && A == number(0)) {
if (in == Pin) { b = (b + 1) % m; ++ba; }
else { a = (a + 1) % m; ++aa; }
} else if (C >= number(0)) {
if (A > number(0)) { if (in == Pin) R.push_back(P[a]); a = (a+1)%n; ++aa; }
else { if (in == Qin) R.push_back(Q[b]); b = (b+1)%m; ++ba; }
} else {
if (B > number(0)) { if (in == Qin) R.push_back(Q[b]); b = (b+1)%m; ++ba; }
else { if (in == Pin) R.push_back(P[a]); a = (a+1)%n; ++aa; }
}
} while ( (aa < n || ba < m) && aa < 2*n && ba < 2*m );
if (in == Unknown) {
if (contains(Q, P[0])) return P;
if (contains(P, Q[0])) return Q;
}
return R;
}
示例2: perimeter
double perimeter(polygon p){
double per = 0.0;
for(int i = 0; i < p.size(); i++){
per += dist(p[i], p[(i+1)%p.size()]);
}
return per;
}
示例3: area
double area(polygon& poly){
double ret = 0.0;
for(int i = 0; i < poly.size(); i++){
ret += trap(poly[i], poly[(i+1)%poly.size()]);
}
return fabs(ret);
}
示例4: inside_poly
//testa se o ponto esta dentro de um poligono (nao necessariamente convexo)
bool inside_poly(pt p, polygon poly){
poly.push_back(poly[0]);
for(int i = 0; i < poly.size()-1; i++)
if(point_and_seg(poly[i], poly[i+1], p)) return true; //na borda
for(int i = 0; i < poly.size()-1; i++) poly[i] = poly[i] - p;
p = pt(0, 0);
double theta, y;
while(true){
theta = (double)rand()/10000.0;
bool inter = false;
//evita que um ponto fique no eixo x
for(int i = 0; i < poly.size()-1; i++){
poly[i] = rotate(poly[i], theta);
if( !cmp(poly[i].x) ) inter = true;
}
if( !inter ){
poly[poly.size()-1] = poly[0];
//testa as possiveis intersecoes
for(int i = 0; i < poly.size()-1; i++){
if( cmp( poly[i].x * poly[i+1].x ) < 0 ){
y = poly[i+1].y - poly[i+1].x * (poly[i].y - poly[i+1].y) / (poly[i].x - poly[i+1].x);
if( cmp(y) > 0 ) inter = !inter; //se interecao valida
}
}
return inter; //testa a paridade da semi-reta vertical partindo de p
}
}
return true;
}
示例5: inside_convex_poly
//testa se o ponto esta no poligono convexo
bool inside_convex_poly(pt p, polygon& poly){
int left = 0, right = 0, side;
for(int i = 0; i < poly.size(); i++){
side = side_sign(p, poly[i], poly[(i+1)%poly.size()]);
if(side < 0) right++;
if(side > 0) left++;
}
return !(left && right);
}
示例6: is_convex
//Determina se o poligono simples eh convexo
bool is_convex(polygon& p){
int left = 0, right = 0, side;
for(int i = 0; i < p.size(); i++){
side = side_sign(p[i], p[(i+1)%p.size()], p[(i+2)%p.size()]);
if(side < 0) right++;
if(side > 0) left++;
}
return !(left && right);
}
示例7: dist
double dist(const polygon &a, const polygon &b) {
double ret = 1e100;
for (int i = 0; i < (int)a.size() - 1; ++ i)
for (int j = 0; j < (int)b.size() - 1; ++ j) {
ret = min(ret, dist(a[i], b[j], b[j + 1]));
ret = min(ret, dist(b[j], a[i], a[i + 1]));
}
return ret;
}
示例8: positiveArea
bool positiveArea(polygon p) {
for (int i = 0; i < p.size(); ++i) {
for (int j = i + 1; j < p.size(); ++j) {
for (int k = j + 1; k < p.size(); ++k) {
if (collineal(p[0], p[1], p[2])) return false;
}
}
}
return true;
}
示例9: polygonintersect
bool polygonintersect(const polygon &a, const polygon &b) {
for (int i = 0; i < (int)a.size() - 1; ++ i)
if (inside(a[i], b)) return true;
for (int i = 0; i < (int)b.size() - 1; ++ i)
if (inside(b[i], a)) return true;
for (int i = 0; i < (int)a.size() - 1; ++ i)
for (int j = 0; j < (int)b.size() - 1; ++ j)
if (intersect(a[i], a[i + 1], b[j], b[j + 1]))
return true;
return false;
}
示例10: polygonIntersects
// 두 다각형이 서로 닿거나 겹치는지 여부를 반환한다.
// 한 점이라도 겹친다면 true 를 반환한다.
bool polygonIntersects(const polygon& p, const polygon& q) {
int n = p.size(), m = q.size();
// 우선 한 다각형이 다른 다각형에 포함되어 있는 경우를 확인하자
if(isInside(p[0], q) || isInside(q[0], p)) return true;
// 이외의 경우, 두 다각형이 서로 겹친다면 서로 닿는 두 변이 반드시 존재한다
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(segmentIntersects(p[i], p[(i+1)%n], q[j], q[(j+1)%m]))
return true;
return false;
}
示例11: centroid
pt centroid(polygon p){
double a = area(p);
double xc = 0.0, yc = 0.0;
for(int i = 0; i < p.size(); i++){
int next = (i+1)%p.size();
xc += (p[i].x + p[next].x)*(p[i].x*p[next].y - p[next].x*p[i].y);
yc += (p[i].y + p[next].y)*(p[i].x*p[next].y - p[next].x*p[i].y);
}
return pt(xc/(6.0*a), yc/(6.0*a));
}
示例12: isPointInPolygon
int isPointInPolygon(point p, polygon &pg)
{
bool in = false;
for (int i = 0; i < pg.size(); i++)
{
point a = pg[i] - p, b = pg[(i + 1) % pg.size()] - p;
if (abs(cross(a, b)) < EPSILON && dot(a, b) < EPSILON) return ON;
if (a.y > b.y) swap(a, b);
if (a.y < EPSILON && EPSILON < b.y && cross(a, b) > EPSILON) in = !in;
}
return in ? IN : OUT;
}
示例13: isugly
bool isugly(const polygon <float> & pol)
{
if (pol.size() < 3)
return true;
//Add other ugly conditions
return false;
}
示例14: in_poly
int in_poly(point p, polygon& T) {
double a = 0; int N = T.size();
for (int i = 0; i < N; i++) {
if (between(T[i], p, T[(i+1) % N])) return -1;
a += angle(T[i], p, T[(i+1) % N]);
}
return cmp(a) != 0;
}
示例15: add_polygon
/**
* @brief Add a polygon to the mesh.
* @param p
*/
void Mesh::add_polygon( polygon& p )
{
polygons.push_back( p );
if ( p.size() == 3 ) {
tris.push_back( p.at(0) );
tris.push_back( p.at(1) );
tris.push_back( p.at(2) );
}
if ( p.size() == 4 ) {
quads.push_back( p.at(0) );
quads.push_back( p.at(1) );
quads.push_back( p.at(2) );
quads.push_back( p.at(3) );
}
}