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

  • Home
  • SEARCH
  • 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 6576931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:21+00:00 2026-05-25T15:34:21+00:00

I currently have a vector of points vector<Point> corners; where I have previously stored

  • 0

I currently have a vector of points

vector<Point> corners;

where I have previously stored the corner points of a given polygon. Given that, I know for sure that the points form a simple polygon that does not contain any self-intersecting edges. However, in the process of storing these vertices, the order in which they connect to each other was not preserved.

I now have a function that, given a vector of points, connects them and draws me a closed figure. However, I need to give this function the sequence of points in the order they need to be connected. Can anyone suggest a way that I could sort these points in the correct order? They form a very simple concave polygon, not a convex hull. An algorithm to find the center point among all the (7) points would also be helpful 🙂

  • 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-25T15:34:22+00:00Added an answer on May 25, 2026 at 3:34 pm

    1. Heuristic to determine the shape

    There is no unique solution so there is no simple algorithm. You could try to somehow mimic your intuition.

    • start by a random point and connect each point to its closest neighbor. Then connect the last point to the first one.
    • start by selecting a point and its closest neighbor and connect them by a line. Now iteratively add another point. Always select the point which minimizes the angle between the last line segment and the newly added line segment.

    Both methods don’t really work in general, they don’t even guarantee to avoid intersections. You can try to address this by backtracking, if you detect an obvious error (e.g. an intersection) then backtrack to the last point of decision and take the “second best” approach instead, ….

    But again as the solution is not unique, don’t expect too much from those heuristics.

    2. Average of the vertices

    The average point for the vertices is easy to compute. Just add all points together and divide through the number of points you just added, this is the average. What you are probably more interested is the center point in the sense of “Center of mass”, see below.

    3. Center point

    To determine the center of mass you first have to define the shape. That means you have to do something like step 1.

    An easily implemented method to compute the center point given the polygon is.

    • Put a bounding box around the polygon.
    • Randomly generate points inside the bounding box.
    • For each of those points determine if it is inside the bounding box, if not, then throw it away. To determine if a point is inside an arbitrary polygon use a ray test.
    • For all points that you kept, apply approach 2. The Average point of those points is a good approximation to the center point.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have created a List of pointers that point to every 5th element
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have links w/ class=ajax that I want to retrieve the element with
I currently have a UINavigationController based application that works just fine. I'd like to
I'm currently working on a C++ project that needs to have as few external
I'm currently developing a syntaxic analyser class that needs, at a point of the
I am working with a std::vector to hold some objects that have dynamically allocated
I have a point defined by x,y and a vector defined by heading, speed.
Given that I have the following in my knowledge-database: 1 0 6 20 0
I have a very large multidimensional vector that changes in size all the time.

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.