Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:41+00:00 2026-05-26T10:40:41+00:00

Based on How to determine if a list of polygon points are in clockwise

  • 0

Based on How to determine if a list of polygon points are in clockwise order?

I’ve come up with the following code:

bool PointsClockwise(const std::vector<MyPoint>& points)
{  
  double sum = 0.0;
  for(size_t i = 0; i < points.size() - 1; ++i)
    sum += (points[i+1].x()-points[i].x()) * (points[i+1].y()+points[i].y());

  return sum > 0.0;
}

However, this seems to have wrong result in certain cases. Take for example the following ring:

LINESTRING(0 119,0 60,694 70,704 72,712 77,719 83,723 92,725 102,723 111,719 120,712 126,703 130)

It is in counter-clockwise order, but the function returns true.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:40:42+00:00Added an answer on May 26, 2026 at 10:40 am

    You missed one of the line segments from your summation – namely the one connecting the last point with the first.
    Try that:

    bool PointsClockwise(const std::vector<MyPoint>& points)
    {  
      double sum = 0.0;
      for(size_t i = 0; i < points.size() - 1; ++i)
        sum += (points[i+1].x()-points[i].x()) * (points[i+1].y()+points[i].y());
    
      sum += (points[0].x()-points[points.size()-1].x()) * (points[0].y()+points[points.size()-1].y());
    
      return sum > 0.0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to determine the StringFormat of some bound TextBlocks at runtime based on
I'm trying to create a form that based on the users input would determine
based on .designer.cs, i infer that the menu's arrangement is based on the order
I am attempting to filter a list based on a predicate Func. I use
I'm making a little web based game and need to determine where to put
My app shows a list of 9 categories and each category displays a Gallery-based
I am attempting to determine prior art for the following idea: 1) user types
I am trying to determine the best method of collecting a large list from
I am going brain dead on this; I have several List' defined, based on
is it possible to determine the ArrayList-index of an element inside the ArrayList based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.