void Polygroup::removePoly(const Poly& poly) { int polyX(poly.getPoint(0).x), polyZ(poly.getPoint(0).z); //Remove poly from the grid for(std::vector<Poly>::iterator gridIt(grid[polyX][polyZ].begin());gridIt!=grid[polyX][polyZ].end();++gridIt) { if((*gridIt)==poly) { grid[polyX][polyZ].erase(gridIt); } } //Remove poly from the low efficiency poly list for(std::vector<Poly>::iterator lowIt(lowEfficientPolys.begin());lowIt!=lowEfficientPolys.end();++lowIt) { if((*lowIt)==poly) { lowEfficientPolys.erase(lowIt); } } if(!initialSetup) { //create a new thread and run the polygon reduction again } }
void Polygroup::addPoly(const Poly& poly) { bool add(true); int polyX(poly.getPoint(0).x), polyZ(poly.getPoint(0).z); for(std::vector<Poly>::iterator gridIt(grid[polyX][polyZ].begin());gridIt!=grid[polyX][polyZ].end();++gridIt) { if((*gridIt)==poly) { add=false; } } if(add){ grid[polyX][polyZ].push_back(poly); lowEfficientPolys.push_back(poly); if(!initialSetup) { //create a new thread and run the polygon reduction again } else { highEfficientPolys.push_back(poly); } } }
vector<Poly> triangulate( const Poly &p ){ vector<Poly> res; int n = p.size(); vector<int> l, r; for( int i = 0; i < n; i++){ l.push_back( ( i - 1 + n) % n ); r.push_back( ( i + 1) % n ); } int i = n - 1, cagao = 0; while( res.size() < n - 2 ){ if ( cagao >= n ) return vector<Poly>(); i = r[i]; Poly tmp; tmp.push_back( p[l[i]] ); tmp.push_back( p[i] ); tmp.push_back( p[r[i]] ); if ( can( tmp, p , l[i], i , r[i] ) ){ res.push_back( tmp ); l[ r[i] ] = l[i]; r[ l[i] ] = r[i]; cagao = 0; }else cagao++; } return res; }
/* Enter n for polygon 5 Enter points of polygon in clockwise/anticlockwise order\n -20 50 50 200 120 50 50 -200 -20 50 Enter rectangle 0 -100 100 150 */ int main() { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, ""); setbkcolor(WHITE); cleardevice(); drawAxis(BLACK); int n; Poly *head = NULL; printf("Enter n for polygon"); scanf("%d", &n); printf("Enter points of polygon in clockwise/anticlockwise order\n"); for(int i = 0; i<n; i++) { Point p; scanf("%lf%lf",&p.x,&p.y); Poly *x = (Poly *) malloc (sizeof(Poly)); *x = {p, head}; head = x; } head->plotPoly(MAGENTA,0); Rect r; printf("Enter rectangle\n"); scanf("%lf%lf%lf%lf",&r.min.x, &r.min.y, &r.max.x, &r.max.y); r.plotRect(BLUE); Poly *op = sutherlandHodgeman(head, &r); op->plotPoly(YELLOW,0); getch(); return 0; }
void CWet_hView::OnTopographiccalculationSideofstream() { MapLayer *pSourceLayer = gpMapWnd->m_pMap->GetLayer( "Cells" ); MapLayer *pToLayer = gpMapWnd->m_pMap->GetLayer("STRGRID"); MapLayer *pFlowDirectionLayer = gpMapWnd->m_pMap->GetLayer("FLOWDIR"); int colToSet = pSourceLayer->GetFieldCol("SIDE"); int thisCount = pSourceLayer->GetRecordCount(); int order = -1; for ( int i=0; i < thisCount; i++ ) { Poly *pPoly = pSourceLayer->GetPolygon(i); float test = pPoly->GetArea(); Vertex centroid = pPoly->GetCentroid(); // int colOrder = pSourceLayer->GetFieldCol("ORDER"); // pSourceLayer->GetData(i,colOrder,order); int side = -1; // if (order == 1) // side = 0; // else // { int row = 0; int col = 0; pFlowDirectionLayer->GetGridCellFromCoord( centroid.x, centroid.y, row, col); side = pFlowDirectionLayer->GetSideOfStream(row, col, pToLayer); // } pSourceLayer->SetData(i, colToSet, side); } }
int main(){ int runs; cin >> runs; for( int r = 1; r <= runs; r++){ string s; cin >> s; Point cur( 0, 0 ); Poly p; for( int i = 0; i < s.size(); i++){ switch(s[i]){ case 'D': cur = Point( cur.x - 1 , cur. y); p.push_back( cur ) ; break; case 'U': cur = Point( cur.x + 1 , cur. y); p.push_back( cur ) ; break; case 'R': cur = Point( cur.x , cur. y + 1); p.push_back( cur ) ; break; case 'L': cur = Point( cur.x , cur. y - 1); p.push_back( cur ) ; break; } } printf("case %d: %.lf\n", r, area( p )); } return 0; }
int main(){ int runs; scanf("%d",&runs ); while( runs-- ){ int n; scanf("%d",&n); Poly R; double S = 0; while( n--) { double w, h, a, x , y; Point c; scanf("%lf%lf%lf%lf%lf", &c.x, &c.y, &w,&h,&a ); a = a * M_PI / 180.0; S += w * h ; w /= 2; h /= 2; R.push_back( c + rot( Point( w, h ) , a ) ); R.push_back( c + rot( Point( w, -h ) , a ) ); R.push_back( c + rot( Point( -w, h ) , a ) ); R.push_back( c + rot( Point( -w, -h ) , a ) ); } double Total = area( convexHull( R ) ); printf("%.1lf %%\n", S/Total*100 ); } return 0; }
Poly PolyXY::F(const ZZn& y) { Poly r; term *pos=NULL; int i,maxy=0; ZZn f; termXY *ptr=start; while (ptr!=NULL) { if (ptr->ny>maxy) maxy=ptr->ny; ptr=ptr->next; } // max y is max power of y present ZZn *pw=new ZZn[maxy+1]; // powers of y pw[0]=(ZZn)1; for (i=1; i<=maxy; i++) pw[i]=y*pw[i-1]; ptr=start; while (ptr!=NULL) { pos=r.addterm(ptr->an*pw[ptr->ny],ptr->nx,pos); ptr=ptr->next; } delete [] pw; return r; }
/*---------------------------------------------------------------------------------------- * */ int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(winw,winh); glutInitWindowPosition(200,100); glutCreateWindow("03 - Mouse Motion"); int size=3; poly.Add(Vector2f(50*size,10*size)); poly.Add(Vector2f(50*size,130*size)); poly.Add(Vector2f(10*size,130*size)); poly.Add(Vector2f(10*size,90*size)); poly.Add(Vector2f(40*size,70*size)); poly.Add(Vector2f(10*size,50*size)); poly.Add(Vector2f(10*size,10*size)); glutDisplayFunc(Draw); glutReshapeFunc(Resize); glutMouseFunc(MouseButton); glutMotionFunc(MouseMotion); glutPassiveMotionFunc(MousePassiveMotion); glutMainLoop(); }
void ReducerHashPack<Q>::insert(ConstMonoRef multiple, const Poly& poly) { MATHICGB_ASSERT(&poly.ring() == &mRing); if (poly.isZero()) return; NewConstTerm termMultiple = {1, multiple.ptr()}; insertEntry(new (mPool.alloc()) MultipleWithPos(poly, termMultiple)); }
// debe ser antihorario vector<Poly> triangulate( const Poly &p ){ vector<Poly> res; int n = p.size(); vector<int> l, r; for( int i = 0; i < n; i++){ l.push_back( ( i - 1 + n) % n ); r.push_back( ( i + 1) % n ); // crea una lista doblemente enlazada } int i = n - 1, cagao = 0; while( res.size() < n - 2 ){ if ( cagao >= n ) return vector<Poly>(); i = r[i]; // avanza tipo un i++ Poly tmp; tmp.push_back( p[l[i]] ); tmp.push_back( p[i] ); tmp.push_back( p[r[i]] ); // crea un triangulo if ( can( tmp, p , l[i], i , r[i] ) ){ // checa si sirve res.push_back( tmp ); // guardamos la solucion l[ r[i] ] = l[i]; r[ l[i] ] = r[i]; // con estas dos operaciones en O(1) borramos el punto del "medio" del triangulo cagao = 0; // no fallo }else cagao++; // se fue al carajo } return res; }
// arma un poligono simple tipo random con varios puntos void simplePolygon( Poly &p ){ Point c = centerMass( p ) ; for( int i = 0; i < p.size(); i++){ p[i].ang = atan2( c.x - p[i].x , c.y - p[i].y ); } sort( p.begin(), p.end() ); }
// Add b to a or Subs b from a. void sub(Poly& a, const Poly& b) { if(a.size() < b.size()) a.resize(b.size(), 0); for(int i = 0; i < b.size(); ++i) a[i] ^= b[i]; tidy(a); }
Poly pow(const Poly& f,int k) { Poly u; int w,e,b; if (k==0) { u.addterm((ZZn)1,0); return u; } u=f; if (k==1) return u; e=k; b=0; while (k>1) {k>>=1; b++; } w=(1<<b); e-=w; w/=2; while (w>0) { u=(u*u); if (e>=w) { e-=w; u=(u*f); } w/=2; } return u; }
cdouble laguerre_internal_complex(Poly const & p, double x0, double tol, bool & quad_root) { cdouble a = 2*tol; cdouble xk = x0; double n = p.degree(); quad_root = false; const unsigned shuffle_rate = 10; // static double shuffle[] = {0, 0.5, 0.25, 0.75, 0.125, 0.375, 0.625, 0.875, 1.0}; unsigned shuffle_counter = 0; while(std::norm(a) > (tol*tol)) { //std::cout << "xk = " << xk << std::endl; cdouble b = p.back(); cdouble d = 0, f = 0; double err = abs(b); double abx = abs(xk); for(int j = p.size()-2; j >= 0; j--) { f = xk*f + d; d = xk*d + b; b = xk*b + p[j]; err = abs(b) + abx*err; } err *= 1e-7; // magic epsilon for convergence, should be computed from tol cdouble px = b; if(abs(b) < err) return xk; //if(std::norm(px) < tol*tol) // return xk; cdouble G = d / px; cdouble H = G*G - f / px; //std::cout << "G = " << G << "H = " << H; cdouble radicand = (n - 1)*(n*H-G*G); //assert(radicand.real() > 0); if(radicand.real() < 0) quad_root = true; //std::cout << "radicand = " << radicand << std::endl; if(G.real() < 0) // here we try to maximise the denominator avoiding cancellation a = - sqrt(radicand); else a = sqrt(radicand); //std::cout << "a = " << a << std::endl; a = n / (a + G); //std::cout << "a = " << a << std::endl; if(shuffle_counter % shuffle_rate == 0) { //a *= shuffle[shuffle_counter / shuffle_rate]; } xk -= a; shuffle_counter++; if(shuffle_counter >= 90) break; } //std::cout << "xk = " << xk << std::endl; return xk; }
Poly naiveShiftRight(const Poly& p, int i) { Poly res(p.size() - i); for (unsigned j = i; j < p.size(); j++) { res.setBit(j - i, p.bit(j)); } res.computeDegree(); return res; }
void ReducerHashPack<Q>::insertTail(NewConstTerm multiple, const Poly& poly) { MATHICGB_ASSERT(&poly.ring() == &mRing); if (poly.termCount() <= 1) return; auto entry = new (mPool.alloc()) MultipleWithPos(poly, multiple); ++entry->pos; insertEntry(entry); }
//For backward directions that take 2 arguments const Poly operator*(int scale, const Poly &P){ Poly P1 = P; for(int i=0; i < P.getOrder(); i++){ P.coeff[i] *= scale; } P1.set(P.coeff, P.getOrder()-1); return P1; }
//Operator * Scaler Overloading Poly Poly::operator*(const int scale){ Poly P = *this; for(int i=0; i < P.getOrder(); i++){ P.coeff[i] *= scale; } P.set(P.coeff, P.getOrder()-1); return P; }
Poly naiveShiftLeft(const Poly& p, int i) { Poly res(p.size() + i); for (unsigned j = 0; j < p.size(); j++) { res.setBit(i + j, p.bit(j)); } res.computeDegree(); return res; }
Point centerMass( Poly &p ){ Point c( 0 , 0 ) ; for( int i = 0; i < p.size(); i++ ) { c.x += p[i].x ;/// (double)p.size(); c.y += p[i].y ;/// (double)p.size(); } return c / (double) p.size(); }
Poly readTri() { Poly ret; for (int i = 0; i < 3; ++i) { Point p; cin >> p.x >> p.y; ret.push_back(p); } return convexHull(ret); }
void drawPoly(const Poly poly) { sf::VertexArray v(sf::Lines, 2); v[0].color = v[1].color = sf::Color::Red; for (size_t i = 0; i < poly.size(); i++) { v[0].position = poly[i]; v[1].position = poly[(i + 1) % poly.size()]; window.draw(v); } }
vector<p2t::Point*> getP2Tpoints(const Poly &poly) { vector<p2t::Point*> points(poly.size()); for (uint i=0; i<poly.size(); i++) { points[i] = new p2t::Point(poly.vertices[i].x(), poly.vertices[i].y()); } return points; }
void ReducerPackDedup<Q>::insert(ConstMonoRef multiple, const Poly& poly) { if (poly.isZero()) return; mLeadTermKnown = false; NewConstTerm termMultiple = {1, multiple.ptr()}; auto entry = new (mPool.alloc()) MultipleWithPos(poly, termMultiple); entry->computeCurrent(poly.ring()); mQueue.push(entry); }
void ReducerPackDedup<Q>::insertTail(NewConstTerm multiple, const Poly& poly) { if (poly.termCount() <= 1) return; mLeadTermKnown = false; auto entry = new (mPool.alloc()) MultipleWithPos(poly, multiple); ++entry->pos; entry->computeCurrent(poly.ring()); mQueue.push(entry); }
Poly *PartialManager::assignPolyToPart(Part *part) { if (firstFreePolyIndex < synth->getPartialCount()) { Poly *poly = freePolys[firstFreePolyIndex]; freePolys[firstFreePolyIndex] = NULL; firstFreePolyIndex++; poly->setPart(part); return poly; } return NULL; }
Poly invmodxn(const Poly& a,int n) { // Newton's method to find 1/a mod x^n int i,k; Poly b; k=0; while ((1<<k)<n) k++; b.addterm((ZZn)1/a.coeff(0),0); // important that a0 != 0 for (i=1;i<=k;i++) b=modxn (2*b-a*b*b,1<<i); b=modxn(b,n); return b; }
void Printlines::addPoly(const Poly poly, int startindex, double speed, double movespeed) { vector<Vector2d> pvert; poly.getLines(pvert,startindex); assert(pvert.size() % 2 == 0); for (uint i=0; i<pvert.size();i+=2){ addLine(pvert[i], pvert[i+1], speed, movespeed, poly.getExtrusionFactor()); } }
Poly::Poly (const Poly& model){ size = model.get_size(); poly = new double[size]; double* polymodel = model.get_poly(); for (int k = 0 ; k<size ; k++){ poly[k] = polymodel[k]; } }