how to generate random convex quadrilaterals using circles (actually inscribed within circles)?











up vote
1
down vote

favorite












I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.










share|improve this question


















  • 1




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    1 hour ago















up vote
1
down vote

favorite












I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.










share|improve this question


















  • 1




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    1 hour ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.










share|improve this question













I would like to generate random convex quadrilaterals using circles, my tutor has suggested to using randomreal to generate 4 numbers and scale the sum of them to 2pi, and then use trigonometry properties to do that, I do not see how that works, can somebody gives some hints about how I should go with it then I can try it out.







graphics parametricplot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









Chonglin Zhu

315




315








  • 1




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    1 hour ago














  • 1




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    1 hour ago








1




1




"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
1 hour ago




"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
1
down vote













ClearAll[randomQuad]
randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;

SeedRandom[777]
Graphics[{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]]


enter image description here






share|improve this answer




























    up vote
    1
    down vote













    Maybe this way?



    n = 1000;
    x = RandomReal[{0, 2 Pi}, {n, 5}];
    x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
    x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
    quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];


    Convexity test:



    And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)



    True







    share|improve this answer























    • maybe we only use random four points on the circle and to construct a quadrilateral?
      – Chonglin Zhu
      47 mins ago










    • Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
      – Henrik Schumacher
      37 mins ago










    • Thanks, this is very helpful!
      – Chonglin Zhu
      36 mins ago










    • You're welcome!
      – Henrik Schumacher
      35 mins ago











    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    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',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f187990%2fhow-to-generate-random-convex-quadrilaterals-using-circles-actually-inscribed-w%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    ClearAll[randomQuad]
    randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;

    SeedRandom[777]
    Graphics[{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]]


    enter image description here






    share|improve this answer

























      up vote
      1
      down vote













      ClearAll[randomQuad]
      randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;

      SeedRandom[777]
      Graphics[{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]]


      enter image description here






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        ClearAll[randomQuad]
        randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;

        SeedRandom[777]
        Graphics[{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]]


        enter image description here






        share|improve this answer












        ClearAll[randomQuad]
        randomQuad = SortBy[#, ArcTan @@ # &] & /@ RandomPoint[Circle, {#, 4}] &;

        SeedRandom[777]
        Graphics[{Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]]


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        kglr

        175k9197402




        175k9197402






















            up vote
            1
            down vote













            Maybe this way?



            n = 1000;
            x = RandomReal[{0, 2 Pi}, {n, 5}];
            x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
            x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
            quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];


            Convexity test:



            And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)



            True







            share|improve this answer























            • maybe we only use random four points on the circle and to construct a quadrilateral?
              – Chonglin Zhu
              47 mins ago










            • Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
              – Henrik Schumacher
              37 mins ago










            • Thanks, this is very helpful!
              – Chonglin Zhu
              36 mins ago










            • You're welcome!
              – Henrik Schumacher
              35 mins ago















            up vote
            1
            down vote













            Maybe this way?



            n = 1000;
            x = RandomReal[{0, 2 Pi}, {n, 5}];
            x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
            x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
            quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];


            Convexity test:



            And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)



            True







            share|improve this answer























            • maybe we only use random four points on the circle and to construct a quadrilateral?
              – Chonglin Zhu
              47 mins ago










            • Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
              – Henrik Schumacher
              37 mins ago










            • Thanks, this is very helpful!
              – Chonglin Zhu
              36 mins ago










            • You're welcome!
              – Henrik Schumacher
              35 mins ago













            up vote
            1
            down vote










            up vote
            1
            down vote









            Maybe this way?



            n = 1000;
            x = RandomReal[{0, 2 Pi}, {n, 5}];
            x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
            x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
            quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];


            Convexity test:



            And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)



            True







            share|improve this answer














            Maybe this way?



            n = 1000;
            x = RandomReal[{0, 2 Pi}, {n, 5}];
            x[[All, 2 ;;]] *= Divide[(2. Pi), (x.{0., 1., 1., 1., 1.})];
            x = x.UpperTriangularize[ConstantArray[1., {5, 4}]];
            quads = Transpose[{Cos[x], Sin[x]}, {3, 1, 2}];


            Convexity test:



            And @@ (Graphics`PolygonUtils`PolygonConvexQ /@ quads)



            True








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 40 mins ago

























            answered 1 hour ago









            Henrik Schumacher

            47.5k466134




            47.5k466134












            • maybe we only use random four points on the circle and to construct a quadrilateral?
              – Chonglin Zhu
              47 mins ago










            • Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
              – Henrik Schumacher
              37 mins ago










            • Thanks, this is very helpful!
              – Chonglin Zhu
              36 mins ago










            • You're welcome!
              – Henrik Schumacher
              35 mins ago


















            • maybe we only use random four points on the circle and to construct a quadrilateral?
              – Chonglin Zhu
              47 mins ago










            • Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
              – Henrik Schumacher
              37 mins ago










            • Thanks, this is very helpful!
              – Chonglin Zhu
              36 mins ago










            • You're welcome!
              – Henrik Schumacher
              35 mins ago
















            maybe we only use random four points on the circle and to construct a quadrilateral?
            – Chonglin Zhu
            47 mins ago




            maybe we only use random four points on the circle and to construct a quadrilateral?
            – Chonglin Zhu
            47 mins ago












            Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
            – Henrik Schumacher
            37 mins ago




            Certainly, this is a trivial problem in the sense that it can be tackled in many ways. I just tried to make it fast by using as much vectorized operations and matrix arithmetic as possible. On my machine, the code above generates about 3 million quadrilaterals per second.
            – Henrik Schumacher
            37 mins ago












            Thanks, this is very helpful!
            – Chonglin Zhu
            36 mins ago




            Thanks, this is very helpful!
            – Chonglin Zhu
            36 mins ago












            You're welcome!
            – Henrik Schumacher
            35 mins ago




            You're welcome!
            – Henrik Schumacher
            35 mins ago


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Mathematica 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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.


            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%2fmathematica.stackexchange.com%2fquestions%2f187990%2fhow-to-generate-random-convex-quadrilaterals-using-circles-actually-inscribed-w%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

            Quarter-circle Tiles

            build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

            Mont Emei