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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:21:26+00:00 2026-06-16T09:21:26+00:00

I have to make a program to find all convex quadrilaterals from the given

  • 0

I have to make a program to find all convex quadrilaterals from the given list of 2d points.
I have tried it with vector cross product but it doesn’t seem to be a correct solution.

Maybe there is some effective algorithm to this problem but I can not find it.

This is an example case with inputs and outputs:

Input


Number of Points:
6


coordinates of points (x,y):
0 0
0 1
1 0
1 1
2 0
2 1

Output


Number of convex quadrilaterals:
9

  • 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-06-16T09:21:28+00:00Added an answer on June 16, 2026 at 9:21 am

    A quadrilateral is convex if its diagonals intersect. Conversely, if two line segments intersect, then their four endpoints make a convex quadrilateral.

    convex quadrilateral on left, non-convex on right

    Every pair of points gives you a line segment, and every point of intersection between two line segments corresponds to a convex quadrilateral.

    You can find the points of intersection using either the naïve algorithm that compares all pairs of segments, or the Bentley–Ottmann algorithm. The former takes O(n4); and the latter O((n2 + q) log n) (where q is the number of convex quadrilaterals). In the worst case q = Θ(n4) — consider n points on a circle — so Bentley–Ottmann is not always faster.

    Here’s the naïve version in Python:

    import numpy as np
    from itertools import combinations
    
    def intersection(s1, s2):
        """
        Return the intersection point of line segments `s1` and `s2`, or
        None if they do not intersect.
        """
        p, r = s1[0], s1[1] - s1[0]
        q, s = s2[0], s2[1] - s2[0]
        rxs = float(np.cross(r, s))
        if rxs == 0: return None
        t = np.cross(q - p, s) / rxs
        u = np.cross(q - p, r) / rxs
        if 0 < t < 1 and 0 < u < 1:
            return p + t * r
        return None
    
    def convex_quadrilaterals(points):
        """
        Generate the convex quadrilaterals among `points`.
        """
        segments = combinations(points, 2)
        for s1, s2 in combinations(segments, 2):
            if intersection(s1, s2) != None:
                yield s1, s2
    

    And an example run:

    >>> points = map(np.array, [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)])
    >>> len(list(convex_quadrilaterals(points)))
    9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make a program that basically reads x lines from a file
I have over the past 5 days tried to find out why my program
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I need to make the program which have one form that contains PNG image
I have been trying, in vain, to make a program that reads text out
I am new in java. I try to make a program and I have
I am trying to make a simple program with SFML. So far I have
I have a Flash program that needs to make url requests to send data
So I have a huge program and decided I should make one of the
In this program I am trying to make, I have an expression (such as

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.