Orientation of a polygon
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Orientation of a polygon

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Location
    Bangalore, INDIA
    Posts
    45

    Orientation of a polygon

    Hi,

    Is there any way to check the orientation of polygon with the help of boost library? If so, can someone help or guide me with a small example?

    Thanks

  2. #2
    Join Date
    Feb 2005
    Location
    Madrid (Spain)
    Posts
    511

    Re: Orientation of a polygon

    Hi.

    http://debian.fmi.uni-sofia.bg/~serg.../clockwise.htm


    Code:
    int ClockWise(CPoint2D *p,int n)
    {
       int i,j,k;
       int count = 0;
       double z;
    
       if (n < 3)
          return(0);
    
       for (i=0;i<n;i++) {
          j = (i + 1) % n;
          k = (i + 2) % n;
          z  = (p[j].x - p[i].x) * (p[k].y - p[j].y);
          z -= (p[j].y - p[i].y) * (p[k].x - p[j].x);
          if (z < 0)
             count--;
          else if (z > 0)
             count++;
       }
       if (count > 0)
          return(COUNTERCLOCKWISE);
       else if (count < 0)
          return(CLOCKWISE);
       else
          return(0);
    }

    You must define CLOCKWISE, COUNTERCLOCKWISE and CPoint2D class.

    Best regars.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center