Changeset 16a0df in git


Ignore:
Timestamp:
Apr 11, 2012, 3:47:39 PM (11 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
e24341824b73ccd926669238b426c9c0ee24664b
Parents:
c723d80014810aa20eda22cc641eba844c928820
git-author:
Martin Lee <martinlee84@web.de>2012-04-11 15:47:39+02:00
git-committer:
Martin Lee <martinlee84@web.de>2012-05-07 14:11:43+02:00
Message:
chg: added function to compute convex hull of support of two bivariate polynomials
Location:
factory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • factory/cfNewtonPolygon.cc

    rc723d80 r16a0df  
    222222}
    223223
     224int **
     225merge (int ** points1, int sizePoints1, int ** points2, int sizePoints2,
     226       int& sizeResult)
     227{
     228  int i, j;
     229  sizeResult= sizePoints1+sizePoints2;
     230  for (i= 0; i < sizePoints1; i++)
     231  {
     232    for (j= 0; j < sizePoints2; j++)
     233    {
     234      if (points1[i][0] != points2[j][0])
     235        continue;
     236      else
     237      {
     238        if (points1[i][1] != points2[j][1])
     239          continue;
     240        else
     241        {
     242          points2[j][0]= -1;
     243          points2[j][1]= -1;
     244          sizeResult--;
     245        }
     246      }
     247    }
     248  }
     249  if (sizeResult == 0)
     250    return points1;
     251
     252  int ** result= new int *[sizeResult];
     253  for (i= 0; i < sizeResult; i++)
     254    result [i]= new int [2];
     255
     256  int k= 0;
     257  for (i= 0; i < sizePoints1; i++, k++)
     258  {
     259    result[k][0]= points1[i][0];
     260    result[k][1]= points1[i][1];
     261  }
     262  for (i= 0; i < sizePoints2; i++)
     263  {
     264    if (points2[i][0] < 0)
     265      continue;
     266    else
     267    {
     268      result[k][0]= points2[i][0];
     269      result[k][1]= points2[i][1];
     270      k++;
     271    }
     272  }
     273  return result;
     274}
     275
    224276// assumes a bivariate poly as input
    225277int ** newtonPolygon (const CanonicalForm& F, int& sizeOfNewtonPoly)
     
    257309    delete [] points[i];
    258310  delete [] points;
     311
     312  return result;
     313}
     314
     315// assumes a bivariate polys as input
     316int ** newtonPolygon (const CanonicalForm& F, const CanonicalForm& G,
     317                      int& sizeOfNewtonPoly)
     318{
     319  int sizeF= size (F);
     320  int ** pointsF= new int* [sizeF];
     321  for (int i= 0; i < sizeF; i++)
     322    pointsF [i]= new int [2];
     323  int j= 0;
     324  int * buf;
     325  int bufSize;
     326  for (CFIterator i= F; i.hasTerms(); i++)
     327  {
     328    buf= getDegrees (i.coeff(), bufSize);
     329    for (int k= 0; k < bufSize; k++, j++)
     330    {
     331      pointsF [j] [0]= i.exp();
     332      pointsF [j] [1]= buf [k];
     333    }
     334    delete [] buf;
     335  }
     336
     337  int sizeG= size (G);
     338  int ** pointsG= new int* [sizeG];
     339  for (int i= 0; i < sizeG; i++)
     340    pointsG [i]= new int [2];
     341  j= 0;
     342  for (CFIterator i= G; i.hasTerms(); i++)
     343  {
     344    buf= getDegrees (i.coeff(), bufSize);
     345    for (int k= 0; k < bufSize; k++, j++)
     346    {
     347      pointsG [j] [0]= i.exp();
     348      pointsG [j] [1]= buf [k];
     349    }
     350    delete [] buf;
     351  }
     352
     353  int sizePoints;
     354  int ** points= merge (pointsF, sizeF, pointsG, sizeG, sizePoints);
     355
     356  int n= polygon (points, sizePoints);
     357
     358  int ** result= new int* [n];
     359  for (int i= 0; i < n; i++)
     360  {
     361    result [i]= new int [2];
     362    result [i] [0]= points [i] [0];
     363    result [i] [1]= points [i] [1];
     364  }
     365
     366  sizeOfNewtonPoly= n;
     367  for (int i= 0; i < sizeF; i++)
     368    delete [] pointsF[i];
     369  delete [] pointsF;
     370  for (int i= 0; i < sizeG; i++)
     371    delete [] pointsG[i];
     372  delete [] pointsG;
    259373
    260374  return result;
  • factory/cfNewtonPolygon.h

    rc723d80 r16a0df  
    3737///         polygon of F
    3838int ** newtonPolygon (const CanonicalForm& F,///< [in] a bivariate polynomial
     39                      int& sizeOfNewtonPoly  ///< [in, out] size of the result
     40                     );
     41
     42/// compute the convex hull of the support of two bivariate polynomials
     43///
     44/// @return an array of points in the plane which are the vertices of the convex
     45///         hull of the support of F and G
     46int ** newtonPolygon (const CanonicalForm& F,///< [in] a bivariate polynomial
     47                      const CanonicalForm& G,///< [in] a bivariate polynomial
    3948                      int& sizeOfNewtonPoly  ///< [in, out] size of the result
    4049                     );
Note: See TracChangeset for help on using the changeset viewer.