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 3680714
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:36:32+00:00 2026-05-19T03:36:32+00:00

Related to: Polygon Decomposition – Removing Concave Points to Form Convex Polygons I am

  • 0

Related to: Polygon Decomposition – Removing Concave Points to Form Convex Polygons

I am looking for an algorithm to do the following:

The input is an array of 2D points (P0…PN-1). The length N of the array varies (3 ≤ N < ∞)
For any M ≤ N there may or may not be a convex polygon whose vertices are P0…PM-1 in some order.

Note the edges are not necessarily adjacent pairs in the array.

What is the most efficient algorithm to find the maximum M such that this convex polygon exists?

My current algorithm is very inefficient. I test with M=3 then M=4, M=5 etc., compute the hull then test that all P0…PM-1 are vertices of the hull, if not then I break out of the loop and return M-1.

Example #1: [(-2,2), (2,2), (-2,-2), (-1,1)]
Diagram for example #1
result: 3 (because the first three points form a triangle but adding P3 = (-1,1) would make the polygon non-convex)

Example #2: [(-2,2), (2,2), (-2,-2), (1,-1)]
Diagram for example #2
result: 4 (because a convex quadrilateral can be constructed from all 4 points in the array)

Update Example #3: [(-3,3), (3,3), (2,-1), (-3,-3), (3,-3), (-2,1)]
alt text
result: 4.

This example demonstrates why it is not sufficient to take the convex hull of all supplied points and find a prefix that is a subset of it. (3,-3) cannot be part of a convex polygon consisting of the first five points because then the previous point (2,-1) would no longer lie on the hull. But it is (3,-3) that must be rejected, even though it lies on the hull of all six points and (2,-1) does not.

Examples of invalid inputs:

  • [(-1,-1), (0,0)] (too few points)
  • [(-1,-1), (0,0), (1,1), (1, -1)] (first three points are colinear: I would not expect the algorithm to be able to handle this.)
  • 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-19T03:36:32+00:00Added an answer on May 19, 2026 at 3:36 am

    There is a very simple O(m log m) solution to this.

    Given that there are at least 3 points and the first 3 are not collinear:

    1. Find a point, P, in the triangle of the first 3 points.

    2. Sort the 3 points by their angle relative to P (counterclockwise). (This sorted list will be the convex hull)

    3. While we aren’t at the end of the list, find the next point’s position in the sorted list.

    4. If inserting the point will make the polygon concave, goto 6. (This can be checked by just checking the new neighboring two turns and the current turn)

    5. Insert the point and goto 3.

    6. Done.

    The main edge case that you have to handle here is when the insertion is at one of the ends of the list, since the list is actually circular. One simple way to handle this is for each point insert it at its angle and at its angle +- 2pi.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Slightly related to my other question : What is the difference between the following:
I have been looking around for examples related to converting JSON strings to Java
Related to https://stackoverflow.com/questions/139944/where-can-one-find-free-software-icons-images I have a need for free weather-related icons. Specifically, I need
Related to this question , I decided to check the UDFs in my data
Related to this question: URL characters replacement in JSP with UrlRewrite I want to
(Related to Is there a secure Browser Cache? ): Do any of the implementations
Related to this question , what is the best practice for naming a mutex?
Related to: Testing firmware starting a microcontroller simulator/emulator Interpreting assembly code If you are
(Not related to versioning the database schema) Applications that interfaces with databases often have
(See related question: How do I report an error midway through a chunked http

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.