本文整理汇总了C++中Poly类的典型用法代码示例。如果您正苦于以下问题:C++ Poly类的具体用法?C++ Poly怎么用?C++ Poly使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Poly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: polyX
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
}
}
示例2: add
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);
}
}
}
示例3: triangulate
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;
}
示例4: main
/*
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;
}
示例5: OnTopographiccalculationSideofstream
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);
}
}
示例6: main
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;
}
示例7: main
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;
}
示例8: F
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;
}
示例9: insertEntry
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));
}
示例10: triangulate
// 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;
}
示例11: simplePolygon
// 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() );
}
示例12: sub
// 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);
}
示例13: pow
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;
}
示例14: laguerre_internal_complex
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;
}
示例15: naiveShiftRight
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;
}