当前位置: 首页>>代码示例>>C++>>正文


C++ ccw函数代码示例

本文整理汇总了C++中ccw函数的典型用法代码示例。如果您正苦于以下问题:C++ ccw函数的具体用法?C++ ccw怎么用?C++ ccw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ccw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ccw_cmp

int ccw_cmp(const void *a, const void *b){
  Point *p1 = (Point *)a;
  Point *p2 = (Point *)b;
  if (ccw(start_p, *p1, *p2) == CCW) return -1;
  if (ccw(start_p, *p2, *p1) == CCW) return 1;
  return 0;
}
开发者ID:AssaultKoder95,项目名称:codejam,代码行数:7,代码来源:polygon_intersection.cpp

示例2: ccw

bool CLine2d::intersects(const CLine2d& otherLine) const
{
   bool retval = false;

   if (getExtent().intersects(otherLine.getExtent()))
   {
      int ccw0 = ccw(otherLine.m_p0) * ccw(otherLine.m_p1);

      if (ccw0 == 0)
      {
         retval = true;
      }
      else
      {
         int ccw1 = otherLine.ccw(m_p0) * otherLine.ccw(m_p1);

         if (ccw1 == 0)
         {
            retval = true;
         }
         else
         {
            retval = ((ccw0 < 0) && (ccw1 < 0));
         }
      }
   }

   return retval;
}
开发者ID:mpatwa,项目名称:CCEtoODB_Translator,代码行数:29,代码来源:DcaLine2d.cpp

示例3: intersect

bool intersect( Line line1, Line line2 )
{
	return (( ccw(line1.p1, line1.p2, line2.p1)
			* ccw(line1.p1, line1.p2, line2.p2)) <= 0)
		&& (( ccw(line2.p1, line2.p2, line1.p1)
			* ccw(line2.p1, line2.p2, line1.p2)) <= 0);
}
开发者ID:ksyu,项目名称:uvajudge,代码行数:7,代码来源:191.cpp

示例4: main

int main()
{
	srand(time(NULL));

	//points = (point*) calloc(points_count, sizeof(struct point));
	struct point * hull = (point*) calloc(points_count, sizeof(struct point));

	rand_points(&points, points_count, dimxy);

    qsort(points, points_count, sizeof(struct point), cmp_points);

    int hind = 0;
	for(int i=0; i < points_count; i++)
	{
		while (hind >= 2 && !ccw(hull[hind-2], hull[hind-1], points[i])) {hind--;}
        hull[hind++] = points[i];
	}

     for(int i = points_count-2, lim = hind+1; i >= 0; --i)
     {
        while (hind >= lim && !ccw(hull[hind-2], hull[hind-1], points[i])) {hind--;}
        hull[hind++] = points[i];
    } 

    /*printf("hull:");
	for (int i=0; i < hind; i++) { printf("(%d,%d),", hull[i].x, hull[i].y); }
    printf("\n");*/
    
    void * r = realloc(hull, sizeof(struct point) * hind);
    
	int ret = plot(points, points_count, hull, hind);
	
	free(points);
	
}
开发者ID:aetelani,项目名称:flatbit,代码行数:35,代码来源:cv.c

示例5: xsort

/**
 * compute the convex hull of a collection of Points
 *
 * @param points the points as a Vector2 array.
 * @param pointsLength the number of vertices of the polygon.
 * @param retPoly pre allocated array of floats to put the vertices
 * @return the number of points in the polygon 0 if no intersection
 */
int SpotShadow::hull(Vector2* points, int pointsLength, Vector2* retPoly) {
    xsort(points, pointsLength);
    int n = pointsLength;
    Vector2 lUpper[n];
    lUpper[0] = points[0];
    lUpper[1] = points[1];

    int lUpperSize = 2;

    for (int i = 2; i < n; i++) {
        lUpper[lUpperSize] = points[i];
        lUpperSize++;

        while (lUpperSize > 2 && !ccw(
                lUpper[lUpperSize - 3].x, lUpper[lUpperSize - 3].y,
                lUpper[lUpperSize - 2].x, lUpper[lUpperSize - 2].y,
                lUpper[lUpperSize - 1].x, lUpper[lUpperSize - 1].y)) {
            // Remove the middle point of the three last
            lUpper[lUpperSize - 2].x = lUpper[lUpperSize - 1].x;
            lUpper[lUpperSize - 2].y = lUpper[lUpperSize - 1].y;
            lUpperSize--;
        }
    }

    Vector2 lLower[n];
    lLower[0] = points[n - 1];
    lLower[1] = points[n - 2];

    int lLowerSize = 2;

    for (int i = n - 3; i >= 0; i--) {
        lLower[lLowerSize] = points[i];
        lLowerSize++;

        while (lLowerSize > 2 && !ccw(
                lLower[lLowerSize - 3].x, lLower[lLowerSize - 3].y,
                lLower[lLowerSize - 2].x, lLower[lLowerSize - 2].y,
                lLower[lLowerSize - 1].x, lLower[lLowerSize - 1].y)) {
            // Remove the middle point of the three last
            lLower[lLowerSize - 2] = lLower[lLowerSize - 1];
            lLowerSize--;
        }
    }

    // output points in CW ordering
    const int total = lUpperSize + lLowerSize - 2;
    int outIndex = total - 1;
    for (int i = 0; i < lUpperSize; i++) {
        retPoly[outIndex] = lUpper[i];
        outIndex--;
    }

    for (int i = 1; i < lLowerSize - 1; i++) {
        retPoly[outIndex] = lLower[i];
        outIndex--;
    }
    // TODO: Add test harness which verify that all the points are inside the hull.
    return total;
}
开发者ID:020gzh,项目名称:platform_frameworks_base,代码行数:67,代码来源:SpotShadow.cpp

示例6: intersect

int intersect(Line l1, Line l2)
{
 
  // The following expression evaluates true if both endpoints of each line
  // are on different sides of the other:
  return ((ccw(l1.p1, l1.p2, l2.p1)*ccw(l1.p1, l1.p2, l2.p2)) <= 0)
    && ((ccw(l2.p1, l2.p2, l1.p1)*ccw(l2.p1, l2.p2, l1.p2)) <= 0);
}
开发者ID:jr314159,项目名称:giraffe,代码行数:8,代码来源:collision.c

示例7: return

bool Geometry::checkIntersectionOfLines(
  const Vector2<>& l1p1,
  const Vector2<>& l1p2,
  const Vector2<>& l2p1,
  const Vector2<>& l2p2)
{
  return (((ccw(l1p1, l1p2, l2p1) * ccw(l1p1, l1p2, l2p2)) <= 0)
          && ((ccw(l2p1, l2p2, l1p1) * ccw(l2p1, l2p2, l1p2)) <= 0));
}
开发者ID:RomanMichna,项目名称:diplomovka,代码行数:9,代码来源:Geometry.cpp

示例8: ConvexCut

VP ConvexCut(const VP &ps, L l) {
  VP Q;
  for (int i = 0; i < (int)ps.size(); i++) {
    P A = ps[i], B = ps[(i+1)%ps.size()];
    if (ccw(l.a, l.b, A) != -1) Q.push_back(A);
    if (ccw(l.a, l.b, A) * ccw(l.a, l.b, B) < 0)
      Q.push_back(is_ll((L){A, B}, l));
  }
  return Q;
}
开发者ID:primenumber,项目名称:ProconLib,代码行数:10,代码来源:Convex.cpp

示例9: spsorty

// Recursive Delaunay Triangulation Procedure
// Contains modifications for axis-switching division.
void CDelaunay::build(int lo, int hi, EdgePointer *le, EdgePointer *re, int rows)
{
  EdgePointer a, b, c, ldo, rdi, ldi, rdo, maxx, minx;
  int split, lowrows;
  int low, high;
  SitePointer s1, s2, s3;
  low = lo;
  high = hi;

  if ( low < (high-2) ) {
    // more than three elements; do recursion
    minx = sp[low];
    maxx = sp[high];
    if (rows == 1) {    // time to switch axis of division
      spsorty( sp, low, high);
      rows = 65536;
    }
    lowrows = rows/2;
    split = low - 1 + (int)
      (0.5 + ((double)(high-low+1) * ((double)lowrows / (double)rows)));
    build( low, split, &ldo, &ldi, lowrows );
    build( split+1, high, &rdi, &rdo, (rows-lowrows) );
    doMerge(&ldo, ldi, rdi, &rdo);
    while (orig(ldo) != minx) {
      ldo = rprev(ldo);
    }
    while (orig(rdo) != maxx) {
      rdo = (SitePointer) lprev(rdo);
    }
    *le = ldo;
    *re = rdo;
  }
  else if (low >= (high - 1)) { // two or one points
    a = makeEdge(sp[low], sp[high]);
    *le = a;
    *re = (EdgePointer) sym(a);
  } else { // three points
    // 3 cases: triangles of 2 orientations, and 3 points on a line
    a = makeEdge((s1 = sp[low]), (s2 = sp[low+1]));
    b = makeEdge(s2, (s3 = sp[high]));
    splice((EdgePointer) sym(a), b);
    if (ccw(s1, s3, s2)) {
      c = connectLeft(b, a);
      *le = (EdgePointer) sym(c);
      *re = c;
    } else {
      *le = a;
      *re = (EdgePointer) sym(b);
      if (ccw(s1, s2, s3)) {
        // not colinear
        c = connectLeft(b, a);
      }
    }
  }
}
开发者ID:cile,项目名称:android_packages_apps_Camera,代码行数:57,代码来源:Delaunay.cpp

示例10: convex_cut

// 左側切除
Polygon convex_cut(const Polygon &p, const Line &l){
    Polygon res;
    for(int i = 0; i < p.size(); ++i){
		P a = curr(p,i), b = next(p,i);
        Line tl = Line(a, b);
        if(ccw(l[0], l[1], a) != -1) res.push_back(a);
        if(ccw(l[0], l[1], a) * ccw(l[0], l[1], b) < 0)
            res.push_back(crosspointLL(tl, l));
    }
    return res;
}
开发者ID:blue-jam,项目名称:ProconLibrary,代码行数:12,代码来源:convexcut.cpp

示例11: convex_hull

Polygon convex_hull(vector<Point> ps) {
  int n = ps.size(), k = 0;
  sort(begin(ps), end(ps), comp);
  Polygon ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  ch.resize(k - 1);
  return ch;
}
开发者ID:asi1024,项目名称:ContestLibrary,代码行数:11,代码来源:convex.cpp

示例12: ConvexHull

VP ConvexHull(VP ps) {
  int n = ps.size();
  int k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2 * n);
  for (int i = 0; i < n; ch[k++] = ps[i++])
    while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
    while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
  ch.resize(k - 1);
  return ch;
}
开发者ID:primenumber,项目名称:ProconLib,代码行数:12,代码来源:Convex.cpp

示例13: convexCut

Polygon convexCut(const Polygon &P, const Line &l) {
    Polygon Q;
    for (int i = 0; i < (int)P.size(); i++) {
        Point A = CURR(P, i), B = NEXT(P, i);
        if (ccw(l[0], l[1], A) != -1) {
            Q.push_back(A);
        }
        if (ccw(l[0], l[1], A) * ccw(l[0], l[1], B) < 0) {
            Q.push_back(crosspointSS(Line(A, B), l));
        }
    }
    return Q;
}
开发者ID:ichyo,项目名称:geometory,代码行数:13,代码来源:convex.cpp

示例14: pointCount

bool KarbonCalligraphicShape::flipDetected(const QPointF &p1, const QPointF &p2)
{
    // detect the flip caused by the angle changing 180 degrees
    // thus detect the boundary crossing
    int index = pointCount() / 2;
    QPointF last1 = pointByIndex(KoPathPointIndex(0, index - 1))->point();
    QPointF last2 = pointByIndex(KoPathPointIndex(0, index))->point();

    int sum1 = std::abs(ccw(p1, p2, last1) + ccw(p1, last2, last1));
    int sum2 = std::abs(ccw(p2, p1, last2) + ccw(p2, last1, last2));
    // if there was a flip
    return sum1 < 2 && sum2 < 2;
}
开发者ID:KDE,项目名称:calligra-history,代码行数:13,代码来源:KarbonCalligraphicShape.cpp

示例15: line_segment_distance

double line_segment_distance(L(a,b), L(c,d)) {
    double x = INFINITY;
    if (abs(a - b) < EPS && abs(c - d) < EPS) x = abs(a - c);
    else if (abs(a - b) < EPS) x = abs(a - closest_point(c, d, a, true));
    else if (abs(c - d) < EPS) x = abs(c - closest_point(a, b, c, true));
    else if ((ccw(a, b, c) < 0) != (ccw(a, b, d) < 0) &&
             (ccw(c, d, a) < 0) != (ccw(c, d, b) < 0)) x = 0;
    else {
        x = min(x, abs(a - closest_point(c,d, a, true)));
        x = min(x, abs(b - closest_point(c,d, b, true)));
        x = min(x, abs(c - closest_point(a,b, c, true)));
        x = min(x, abs(d - closest_point(a,b, d, true)));
    }
    return x;
}
开发者ID:Cybuster,项目名称:CompetitiveProgramming,代码行数:15,代码来源:lines.cpp


注:本文中的ccw函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。