Convex Quadrilateral Test The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to determine which type of quadrilateral is by giving the four points of the quadrilateral?Geometry Proof: Convex QuadrilateralConvex polygons partitioned into concave quadrilateralsLargest Quadrilateral from a Set of PointsFive points in the plane are given, no three of which are collinear. Show that some four of them form a convex quadrilateral.Quadrilateral Finite Elements must be convex and not self-intersecting. But why?How to determine which type of quadrilateral is by giving the four points of the quadrilateral?If a disk contains the diagonal of a quadrilateral, it will contain at least one of the vertices not lying on this diagonalFunction to map 2D coordinates from one quadrilateral to anotherIs there other proof of Pascal Points on the sides of the quadrilateral theorem?All relationships between angles formed by drawing diagonals of a quadrilateral

Is a pteranodon too powerful as a beast companion for a beast master?

What can I do if neighbor is blocking my solar panels intentionally?

What are these Gizmos at Izaña Atmospheric Research Center in Spain?

A pet rabbit called Belle

How are presidential pardons supposed to be used?

Can a 1st-level character have an ability score above 18?

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Create an outline of font

how can a perfect fourth interval be considered either consonant or dissonant?

Take groceries in checked luggage

Relations between two reciprocal partial derivatives?

What information about me do stores get via my credit card?

What was the last x86 CPU that did not have the x87 floating-point unit built in?

How to pronounce 1ターン?

Am I ethically obligated to go into work on an off day if the reason is sudden?

The variadic template constructor of my class cannot modify my class members, why is that so?

Did the new image of black hole confirm the general theory of relativity?

How to prevent selfdestruct from another contract

Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?

Are spiders unable to hurt humans, especially very small spiders?

Match Roman Numerals

Empty set is subset of every set? If yes, why that...

Did the UK government pay "millions and millions of dollars" to try to snag Julian Assange?

Segmentation fault output is suppressed when piping stdin into a function. Why?



Convex Quadrilateral Test



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to determine which type of quadrilateral is by giving the four points of the quadrilateral?Geometry Proof: Convex QuadrilateralConvex polygons partitioned into concave quadrilateralsLargest Quadrilateral from a Set of PointsFive points in the plane are given, no three of which are collinear. Show that some four of them form a convex quadrilateral.Quadrilateral Finite Elements must be convex and not self-intersecting. But why?How to determine which type of quadrilateral is by giving the four points of the quadrilateral?If a disk contains the diagonal of a quadrilateral, it will contain at least one of the vertices not lying on this diagonalFunction to map 2D coordinates from one quadrilateral to anotherIs there other proof of Pascal Points on the sides of the quadrilateral theorem?All relationships between angles formed by drawing diagonals of a quadrilateral










5












$begingroup$


I have a four points in plane and need to test (based on point coordinates) whether they are able to form a convex quadrilateral:



convex quadrilateral



Of course, the test should avoid configurations like these:



concave quadrilateral 1



concave quadrilateral 2



Given the diagonals, I can check whether the quadrilateral is convex (simply checking whether the intersection of diagonals is between both ends of both diagonals).



The real problem is how to label the four points and filter out all concave and degenerate configurations (like, for example: $A=B$).



If the labeling is possible (convex case found), the four points should be labeled such that $AC$ and $BD$ are diagonals of a convex quadrialteral.



I wonder if there is an elegant solution (rather than testing every possible permutation of $A, B, C$ and $D$).










share|cite|improve this question











$endgroup$
















    5












    $begingroup$


    I have a four points in plane and need to test (based on point coordinates) whether they are able to form a convex quadrilateral:



    convex quadrilateral



    Of course, the test should avoid configurations like these:



    concave quadrilateral 1



    concave quadrilateral 2



    Given the diagonals, I can check whether the quadrilateral is convex (simply checking whether the intersection of diagonals is between both ends of both diagonals).



    The real problem is how to label the four points and filter out all concave and degenerate configurations (like, for example: $A=B$).



    If the labeling is possible (convex case found), the four points should be labeled such that $AC$ and $BD$ are diagonals of a convex quadrialteral.



    I wonder if there is an elegant solution (rather than testing every possible permutation of $A, B, C$ and $D$).










    share|cite|improve this question











    $endgroup$














      5












      5








      5


      1



      $begingroup$


      I have a four points in plane and need to test (based on point coordinates) whether they are able to form a convex quadrilateral:



      convex quadrilateral



      Of course, the test should avoid configurations like these:



      concave quadrilateral 1



      concave quadrilateral 2



      Given the diagonals, I can check whether the quadrilateral is convex (simply checking whether the intersection of diagonals is between both ends of both diagonals).



      The real problem is how to label the four points and filter out all concave and degenerate configurations (like, for example: $A=B$).



      If the labeling is possible (convex case found), the four points should be labeled such that $AC$ and $BD$ are diagonals of a convex quadrialteral.



      I wonder if there is an elegant solution (rather than testing every possible permutation of $A, B, C$ and $D$).










      share|cite|improve this question











      $endgroup$




      I have a four points in plane and need to test (based on point coordinates) whether they are able to form a convex quadrilateral:



      convex quadrilateral



      Of course, the test should avoid configurations like these:



      concave quadrilateral 1



      concave quadrilateral 2



      Given the diagonals, I can check whether the quadrilateral is convex (simply checking whether the intersection of diagonals is between both ends of both diagonals).



      The real problem is how to label the four points and filter out all concave and degenerate configurations (like, for example: $A=B$).



      If the labeling is possible (convex case found), the four points should be labeled such that $AC$ and $BD$ are diagonals of a convex quadrialteral.



      I wonder if there is an elegant solution (rather than testing every possible permutation of $A, B, C$ and $D$).







      geometry algorithms euclidean-geometry






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Apr 10 '12 at 1:25







      Libor

















      asked Apr 10 '12 at 0:55









      LiborLibor

      8831822




      8831822




















          4 Answers
          4






          active

          oldest

          votes


















          1












          $begingroup$

          You want to know whether all four points are vertices of their convex hull. So find the convex hull using say Jarvis's march and check whether it has four vertices. You'll have to decide what to do when three points are collinear.






          share|cite|improve this answer











          $endgroup$












          • $begingroup$
            Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
            $endgroup$
            – Libor
            Apr 10 '12 at 1:36



















          1












          $begingroup$

          If no points are coincident and only one angle between the vertices rays is greater than 180, then it is concave. Concave quadrilaterals can never form a bow tie. If all the angles between vertices rays are less than 90 degrees, then you have a bow tie. To order the points of a convex quadrilateral, average the vertices to find a median point. Draw a ray from the median point to each vertices. Calculate the angle of each median ray, and sort the vertices by their ray angles. Max to min sorting gives a clockwise quadrilateral, while min to max gives a counter clockwise quadrilateral.






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
            $endgroup$
            – Libor
            Aug 16 '15 at 8:00










          • $begingroup$
            "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
            $endgroup$
            – OJW
            May 3 '17 at 16:33


















          0












          $begingroup$

          Maybe a simpler way to solve this problem would be to write down the four vectors which describe the sides of the polygon, and calculate at each vertex the angle between these vectors. If this angle is ever obtuse, then you don't have a convex polygon. This procedure would only require going through 4 calculations.






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            There is no polygon. Only the points are given.
            $endgroup$
            – lhf
            Apr 10 '12 at 2:12










          • $begingroup$
            So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
            $endgroup$
            – Eric Haengel
            Apr 10 '12 at 2:15











          • $begingroup$
            @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
            $endgroup$
            – Jack Lee
            Apr 10 '12 at 17:35










          • $begingroup$
            oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
            $endgroup$
            – Eric Haengel
            Apr 11 '12 at 4:37










          • $begingroup$
            Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
            $endgroup$
            – Jack Lee
            Apr 11 '12 at 5:54


















          0












          $begingroup$

          Maybe it's too late for an answer to be useful to the OP (7 yrs too late!), but it still might be useful to someone.



          My solution would be to get the barycentric coordinates (how?) of the fourth point, in the triangle formed by the first 3 points, and then using those coordinates to determine where the 4th point is relative to the triangle.



          Explanatory image



          Now all we need to do is make sure that D lies in one of the green areas:



          Vector2[] GetQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)

          // make sure that points A, B and C don't form a degenerate triangle
          Vector2 ab = b - a;
          Vector2 bc = c - b;
          if (ab.Cross(bc) == 0)
          return null; // a, b and c are co-linear

          // Compute barycentric coordinates of point D relative to the triangle ABC
          Vector3 barycentric = Barycentric(d, a, b, c);
          float alpha = barycentric.x, beta = barycentric.y, gamma = barycentric.z;

          // now resolve...
          if (alpha < 0 && beta > 0 && gamma > 0) // d lies in the top-right green area
          return new Vector2[] a, b, d, c ;
          else if (alpha > 0 && beta < 0 && gamma > 0) // d lies in the bottom green area
          return new Vector2[] a, b, c, d ;
          else if (alpha > 0 && beta > 0 && gamma < 0) // d lies in the top-left green area
          return new Vector2[] a, d, b, c ;
          else
          return null;






          share|cite|improve this answer











          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "69"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            noCode: true, onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f129854%2fconvex-quadrilateral-test%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1












            $begingroup$

            You want to know whether all four points are vertices of their convex hull. So find the convex hull using say Jarvis's march and check whether it has four vertices. You'll have to decide what to do when three points are collinear.






            share|cite|improve this answer











            $endgroup$












            • $begingroup$
              Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
              $endgroup$
              – Libor
              Apr 10 '12 at 1:36
















            1












            $begingroup$

            You want to know whether all four points are vertices of their convex hull. So find the convex hull using say Jarvis's march and check whether it has four vertices. You'll have to decide what to do when three points are collinear.






            share|cite|improve this answer











            $endgroup$












            • $begingroup$
              Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
              $endgroup$
              – Libor
              Apr 10 '12 at 1:36














            1












            1








            1





            $begingroup$

            You want to know whether all four points are vertices of their convex hull. So find the convex hull using say Jarvis's march and check whether it has four vertices. You'll have to decide what to do when three points are collinear.






            share|cite|improve this answer











            $endgroup$



            You want to know whether all four points are vertices of their convex hull. So find the convex hull using say Jarvis's march and check whether it has four vertices. You'll have to decide what to do when three points are collinear.







            share|cite|improve this answer














            share|cite|improve this answer



            share|cite|improve this answer








            edited Apr 10 '12 at 1:32

























            answered Apr 10 '12 at 1:19









            lhflhf

            168k11172404




            168k11172404











            • $begingroup$
              Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
              $endgroup$
              – Libor
              Apr 10 '12 at 1:36

















            • $begingroup$
              Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
              $endgroup$
              – Libor
              Apr 10 '12 at 1:36
















            $begingroup$
            Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
            $endgroup$
            – Libor
            Apr 10 '12 at 1:36





            $begingroup$
            Thanks. In my original problem, I have a transform that maps 4-points to another 4-points (i.e. planar homography that maps e.g. perspectively distorted view to an undistored one). I found one implementation, where they check whether any three points are colinear. However, what if the points form a deltoid? Then no three points are colinear and still the quadrilateral is concave.
            $endgroup$
            – Libor
            Apr 10 '12 at 1:36












            1












            $begingroup$

            If no points are coincident and only one angle between the vertices rays is greater than 180, then it is concave. Concave quadrilaterals can never form a bow tie. If all the angles between vertices rays are less than 90 degrees, then you have a bow tie. To order the points of a convex quadrilateral, average the vertices to find a median point. Draw a ray from the median point to each vertices. Calculate the angle of each median ray, and sort the vertices by their ray angles. Max to min sorting gives a clockwise quadrilateral, while min to max gives a counter clockwise quadrilateral.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
              $endgroup$
              – Libor
              Aug 16 '15 at 8:00










            • $begingroup$
              "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
              $endgroup$
              – OJW
              May 3 '17 at 16:33















            1












            $begingroup$

            If no points are coincident and only one angle between the vertices rays is greater than 180, then it is concave. Concave quadrilaterals can never form a bow tie. If all the angles between vertices rays are less than 90 degrees, then you have a bow tie. To order the points of a convex quadrilateral, average the vertices to find a median point. Draw a ray from the median point to each vertices. Calculate the angle of each median ray, and sort the vertices by their ray angles. Max to min sorting gives a clockwise quadrilateral, while min to max gives a counter clockwise quadrilateral.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
              $endgroup$
              – Libor
              Aug 16 '15 at 8:00










            • $begingroup$
              "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
              $endgroup$
              – OJW
              May 3 '17 at 16:33













            1












            1








            1





            $begingroup$

            If no points are coincident and only one angle between the vertices rays is greater than 180, then it is concave. Concave quadrilaterals can never form a bow tie. If all the angles between vertices rays are less than 90 degrees, then you have a bow tie. To order the points of a convex quadrilateral, average the vertices to find a median point. Draw a ray from the median point to each vertices. Calculate the angle of each median ray, and sort the vertices by their ray angles. Max to min sorting gives a clockwise quadrilateral, while min to max gives a counter clockwise quadrilateral.






            share|cite|improve this answer









            $endgroup$



            If no points are coincident and only one angle between the vertices rays is greater than 180, then it is concave. Concave quadrilaterals can never form a bow tie. If all the angles between vertices rays are less than 90 degrees, then you have a bow tie. To order the points of a convex quadrilateral, average the vertices to find a median point. Draw a ray from the median point to each vertices. Calculate the angle of each median ray, and sort the vertices by their ray angles. Max to min sorting gives a clockwise quadrilateral, while min to max gives a counter clockwise quadrilateral.







            share|cite|improve this answer












            share|cite|improve this answer



            share|cite|improve this answer










            answered Aug 15 '15 at 1:08









            GeneGene

            111




            111











            • $begingroup$
              This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
              $endgroup$
              – Libor
              Aug 16 '15 at 8:00










            • $begingroup$
              "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
              $endgroup$
              – OJW
              May 3 '17 at 16:33
















            • $begingroup$
              This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
              $endgroup$
              – Libor
              Aug 16 '15 at 8:00










            • $begingroup$
              "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
              $endgroup$
              – OJW
              May 3 '17 at 16:33















            $begingroup$
            This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
            $endgroup$
            – Libor
            Aug 16 '15 at 8:00




            $begingroup$
            This looks like an efficient solution. I have finally used Cramer's Rule to check whether intersection of diagonals lays inside the quadrilateral.
            $endgroup$
            – Libor
            Aug 16 '15 at 8:00












            $begingroup$
            "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
            $endgroup$
            – OJW
            May 3 '17 at 16:33




            $begingroup$
            "If all the angles between vertices rays are less than 90 degrees, then you have a bow tie" -- you can make bow tie using two angles of 90 degrees and 2 angles < 90.
            $endgroup$
            – OJW
            May 3 '17 at 16:33











            0












            $begingroup$

            Maybe a simpler way to solve this problem would be to write down the four vectors which describe the sides of the polygon, and calculate at each vertex the angle between these vectors. If this angle is ever obtuse, then you don't have a convex polygon. This procedure would only require going through 4 calculations.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              There is no polygon. Only the points are given.
              $endgroup$
              – lhf
              Apr 10 '12 at 2:12










            • $begingroup$
              So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
              $endgroup$
              – Eric Haengel
              Apr 10 '12 at 2:15











            • $begingroup$
              @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
              $endgroup$
              – Jack Lee
              Apr 10 '12 at 17:35










            • $begingroup$
              oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
              $endgroup$
              – Eric Haengel
              Apr 11 '12 at 4:37










            • $begingroup$
              Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
              $endgroup$
              – Jack Lee
              Apr 11 '12 at 5:54















            0












            $begingroup$

            Maybe a simpler way to solve this problem would be to write down the four vectors which describe the sides of the polygon, and calculate at each vertex the angle between these vectors. If this angle is ever obtuse, then you don't have a convex polygon. This procedure would only require going through 4 calculations.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              There is no polygon. Only the points are given.
              $endgroup$
              – lhf
              Apr 10 '12 at 2:12










            • $begingroup$
              So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
              $endgroup$
              – Eric Haengel
              Apr 10 '12 at 2:15











            • $begingroup$
              @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
              $endgroup$
              – Jack Lee
              Apr 10 '12 at 17:35










            • $begingroup$
              oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
              $endgroup$
              – Eric Haengel
              Apr 11 '12 at 4:37










            • $begingroup$
              Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
              $endgroup$
              – Jack Lee
              Apr 11 '12 at 5:54













            0












            0








            0





            $begingroup$

            Maybe a simpler way to solve this problem would be to write down the four vectors which describe the sides of the polygon, and calculate at each vertex the angle between these vectors. If this angle is ever obtuse, then you don't have a convex polygon. This procedure would only require going through 4 calculations.






            share|cite|improve this answer









            $endgroup$



            Maybe a simpler way to solve this problem would be to write down the four vectors which describe the sides of the polygon, and calculate at each vertex the angle between these vectors. If this angle is ever obtuse, then you don't have a convex polygon. This procedure would only require going through 4 calculations.







            share|cite|improve this answer












            share|cite|improve this answer



            share|cite|improve this answer










            answered Apr 10 '12 at 2:10









            Eric HaengelEric Haengel

            3,03411531




            3,03411531











            • $begingroup$
              There is no polygon. Only the points are given.
              $endgroup$
              – lhf
              Apr 10 '12 at 2:12










            • $begingroup$
              So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
              $endgroup$
              – Eric Haengel
              Apr 10 '12 at 2:15











            • $begingroup$
              @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
              $endgroup$
              – Jack Lee
              Apr 10 '12 at 17:35










            • $begingroup$
              oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
              $endgroup$
              – Eric Haengel
              Apr 11 '12 at 4:37










            • $begingroup$
              Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
              $endgroup$
              – Jack Lee
              Apr 11 '12 at 5:54
















            • $begingroup$
              There is no polygon. Only the points are given.
              $endgroup$
              – lhf
              Apr 10 '12 at 2:12










            • $begingroup$
              So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
              $endgroup$
              – Eric Haengel
              Apr 10 '12 at 2:15











            • $begingroup$
              @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
              $endgroup$
              – Jack Lee
              Apr 10 '12 at 17:35










            • $begingroup$
              oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
              $endgroup$
              – Eric Haengel
              Apr 11 '12 at 4:37










            • $begingroup$
              Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
              $endgroup$
              – Jack Lee
              Apr 11 '12 at 5:54















            $begingroup$
            There is no polygon. Only the points are given.
            $endgroup$
            – lhf
            Apr 10 '12 at 2:12




            $begingroup$
            There is no polygon. Only the points are given.
            $endgroup$
            – lhf
            Apr 10 '12 at 2:12












            $begingroup$
            So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
            $endgroup$
            – Eric Haengel
            Apr 10 '12 at 2:15





            $begingroup$
            So is the problem to construct a convex polygon from those points? Just given 4 points, most polygons formed from those points are not convex.
            $endgroup$
            – Eric Haengel
            Apr 10 '12 at 2:15













            $begingroup$
            @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
            $endgroup$
            – Jack Lee
            Apr 10 '12 at 17:35




            $begingroup$
            @EricHaengel: I don't understand your answer. Most convex quadrilaterals have obtuse angles -- in fact, because the interior angle sum of every quadrilateral is $360^circ$, the only convex quadrilaterals that don't have obtuse angles are rectangles.
            $endgroup$
            – Jack Lee
            Apr 10 '12 at 17:35












            $begingroup$
            oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
            $endgroup$
            – Eric Haengel
            Apr 11 '12 at 4:37




            $begingroup$
            oh ha I'm sorry Jack you're right, I mixed up my words. I meant check whether the angles are greater than 180 degrees instead of obtuse.
            $endgroup$
            – Eric Haengel
            Apr 11 '12 at 4:37












            $begingroup$
            Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
            $endgroup$
            – Jack Lee
            Apr 11 '12 at 5:54




            $begingroup$
            Oh, I see. That seems as if it would be a difficult algorithm to implement -- any three noncollinear points taken in some order form one angle with measure less than $180^circ$ and another with measure greater than $180^circ$. If you don't already know where the polygon is, how can you tell which one of those angles to use?
            $endgroup$
            – Jack Lee
            Apr 11 '12 at 5:54











            0












            $begingroup$

            Maybe it's too late for an answer to be useful to the OP (7 yrs too late!), but it still might be useful to someone.



            My solution would be to get the barycentric coordinates (how?) of the fourth point, in the triangle formed by the first 3 points, and then using those coordinates to determine where the 4th point is relative to the triangle.



            Explanatory image



            Now all we need to do is make sure that D lies in one of the green areas:



            Vector2[] GetQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)

            // make sure that points A, B and C don't form a degenerate triangle
            Vector2 ab = b - a;
            Vector2 bc = c - b;
            if (ab.Cross(bc) == 0)
            return null; // a, b and c are co-linear

            // Compute barycentric coordinates of point D relative to the triangle ABC
            Vector3 barycentric = Barycentric(d, a, b, c);
            float alpha = barycentric.x, beta = barycentric.y, gamma = barycentric.z;

            // now resolve...
            if (alpha < 0 && beta > 0 && gamma > 0) // d lies in the top-right green area
            return new Vector2[] a, b, d, c ;
            else if (alpha > 0 && beta < 0 && gamma > 0) // d lies in the bottom green area
            return new Vector2[] a, b, c, d ;
            else if (alpha > 0 && beta > 0 && gamma < 0) // d lies in the top-left green area
            return new Vector2[] a, d, b, c ;
            else
            return null;






            share|cite|improve this answer











            $endgroup$

















              0












              $begingroup$

              Maybe it's too late for an answer to be useful to the OP (7 yrs too late!), but it still might be useful to someone.



              My solution would be to get the barycentric coordinates (how?) of the fourth point, in the triangle formed by the first 3 points, and then using those coordinates to determine where the 4th point is relative to the triangle.



              Explanatory image



              Now all we need to do is make sure that D lies in one of the green areas:



              Vector2[] GetQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)

              // make sure that points A, B and C don't form a degenerate triangle
              Vector2 ab = b - a;
              Vector2 bc = c - b;
              if (ab.Cross(bc) == 0)
              return null; // a, b and c are co-linear

              // Compute barycentric coordinates of point D relative to the triangle ABC
              Vector3 barycentric = Barycentric(d, a, b, c);
              float alpha = barycentric.x, beta = barycentric.y, gamma = barycentric.z;

              // now resolve...
              if (alpha < 0 && beta > 0 && gamma > 0) // d lies in the top-right green area
              return new Vector2[] a, b, d, c ;
              else if (alpha > 0 && beta < 0 && gamma > 0) // d lies in the bottom green area
              return new Vector2[] a, b, c, d ;
              else if (alpha > 0 && beta > 0 && gamma < 0) // d lies in the top-left green area
              return new Vector2[] a, d, b, c ;
              else
              return null;






              share|cite|improve this answer











              $endgroup$















                0












                0








                0





                $begingroup$

                Maybe it's too late for an answer to be useful to the OP (7 yrs too late!), but it still might be useful to someone.



                My solution would be to get the barycentric coordinates (how?) of the fourth point, in the triangle formed by the first 3 points, and then using those coordinates to determine where the 4th point is relative to the triangle.



                Explanatory image



                Now all we need to do is make sure that D lies in one of the green areas:



                Vector2[] GetQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)

                // make sure that points A, B and C don't form a degenerate triangle
                Vector2 ab = b - a;
                Vector2 bc = c - b;
                if (ab.Cross(bc) == 0)
                return null; // a, b and c are co-linear

                // Compute barycentric coordinates of point D relative to the triangle ABC
                Vector3 barycentric = Barycentric(d, a, b, c);
                float alpha = barycentric.x, beta = barycentric.y, gamma = barycentric.z;

                // now resolve...
                if (alpha < 0 && beta > 0 && gamma > 0) // d lies in the top-right green area
                return new Vector2[] a, b, d, c ;
                else if (alpha > 0 && beta < 0 && gamma > 0) // d lies in the bottom green area
                return new Vector2[] a, b, c, d ;
                else if (alpha > 0 && beta > 0 && gamma < 0) // d lies in the top-left green area
                return new Vector2[] a, d, b, c ;
                else
                return null;






                share|cite|improve this answer











                $endgroup$



                Maybe it's too late for an answer to be useful to the OP (7 yrs too late!), but it still might be useful to someone.



                My solution would be to get the barycentric coordinates (how?) of the fourth point, in the triangle formed by the first 3 points, and then using those coordinates to determine where the 4th point is relative to the triangle.



                Explanatory image



                Now all we need to do is make sure that D lies in one of the green areas:



                Vector2[] GetQuad(Vector2 a, Vector2 b, Vector2 c, Vector2 d)

                // make sure that points A, B and C don't form a degenerate triangle
                Vector2 ab = b - a;
                Vector2 bc = c - b;
                if (ab.Cross(bc) == 0)
                return null; // a, b and c are co-linear

                // Compute barycentric coordinates of point D relative to the triangle ABC
                Vector3 barycentric = Barycentric(d, a, b, c);
                float alpha = barycentric.x, beta = barycentric.y, gamma = barycentric.z;

                // now resolve...
                if (alpha < 0 && beta > 0 && gamma > 0) // d lies in the top-right green area
                return new Vector2[] a, b, d, c ;
                else if (alpha > 0 && beta < 0 && gamma > 0) // d lies in the bottom green area
                return new Vector2[] a, b, c, d ;
                else if (alpha > 0 && beta > 0 && gamma < 0) // d lies in the top-left green area
                return new Vector2[] a, d, b, c ;
                else
                return null;







                share|cite|improve this answer














                share|cite|improve this answer



                share|cite|improve this answer








                edited Mar 31 at 14:21

























                answered Mar 31 at 13:06









                Esam BustatyEsam Bustaty

                486




                486



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Mathematics Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f129854%2fconvex-quadrilateral-test%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Boston (Lincolnshire) Stedsbyld | Berne yn Boston | NavigaasjemenuBoston Borough CouncilBoston, Lincolnshire

                    Trouble understanding the speech of overseas colleaguesHow can I better understand manager or clients with strong accents?Adding more movement and speech at the fundamental level to a highly-sedentary job?Difficulty in understanding Manager's accent(language and communication)How to adjust yourself where your colleagues are not understanding to you?Understanding manager's expectationsForeigner and colleagues using slangHaving difficulty understanding meetingsHow do you breathe when giving a speech?Trouble Waking Up for Emergencies (On-Call)Problems with colleaguesColleagues feeling insecure when I do my work

                    Ballerup Komuun Stääden an saarpen | Futnuuten | Luke uk diar | Nawigatsjuunwww.ballerup.dkwww.statistikbanken.dk: Tabelle BEF44 (Folketal pr. 1. januar fordelt på byer)Commonskategorii: Ballerup Komuun55° 44′ N, 12° 22′ O