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












6














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


















  • 3




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    Dec 16 '18 at 15:18
















6














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


















  • 3




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    Dec 16 '18 at 15:18














6












6








6







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 plotting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 16 '18 at 15:05









Chonglin ZhuChonglin Zhu

666




666








  • 3




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    Dec 16 '18 at 15:18














  • 3




    "Use trigonometry" means place them on the unit circle. Then connect the dots.
    – Daniel Lichtblau
    Dec 16 '18 at 15:18








3




3




"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 '18 at 15:18




"Use trigonometry" means place them on the unit circle. Then connect the dots.
– Daniel Lichtblau
Dec 16 '18 at 15:18










3 Answers
3






active

oldest

votes


















6














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
    Dec 16 '18 at 15:48










  • 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
    Dec 16 '18 at 15:59










  • Thanks, this is very helpful!
    – Chonglin Zhu
    Dec 16 '18 at 16:00










  • You're welcome!
    – Henrik Schumacher
    Dec 16 '18 at 16:00



















3














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

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


enter image description here






share|improve this answer































    3














    Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):



    n = 550;
    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}];
    disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
    shiftQuads = quads +
    RandomChoice[Flatten@disks, n]*
    Transpose[
    ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
    Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];

    {
    Opacity[.15],
    Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
    Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
    } // Graphics


    enter image description here






    share|improve this answer





















    • Great! I will have a try, so many thanks!
      – Chonglin Zhu
      Dec 18 '18 at 2:30











    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',
    autoActivateHeartbeat: false,
    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

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    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
      Dec 16 '18 at 15:48










    • 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
      Dec 16 '18 at 15:59










    • Thanks, this is very helpful!
      – Chonglin Zhu
      Dec 16 '18 at 16:00










    • You're welcome!
      – Henrik Schumacher
      Dec 16 '18 at 16:00
















    6














    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
      Dec 16 '18 at 15:48










    • 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
      Dec 16 '18 at 15:59










    • Thanks, this is very helpful!
      – Chonglin Zhu
      Dec 16 '18 at 16:00










    • You're welcome!
      – Henrik Schumacher
      Dec 16 '18 at 16:00














    6












    6








    6






    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 Dec 16 '18 at 15:55

























    answered Dec 16 '18 at 15:16









    Henrik SchumacherHenrik Schumacher

    49.8k469143




    49.8k469143












    • maybe we only use random four points on the circle and to construct a quadrilateral?
      – Chonglin Zhu
      Dec 16 '18 at 15:48










    • 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
      Dec 16 '18 at 15:59










    • Thanks, this is very helpful!
      – Chonglin Zhu
      Dec 16 '18 at 16:00










    • You're welcome!
      – Henrik Schumacher
      Dec 16 '18 at 16:00


















    • maybe we only use random four points on the circle and to construct a quadrilateral?
      – Chonglin Zhu
      Dec 16 '18 at 15:48










    • 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
      Dec 16 '18 at 15:59










    • Thanks, this is very helpful!
      – Chonglin Zhu
      Dec 16 '18 at 16:00










    • You're welcome!
      – Henrik Schumacher
      Dec 16 '18 at 16:00
















    maybe we only use random four points on the circle and to construct a quadrilateral?
    – Chonglin Zhu
    Dec 16 '18 at 15:48




    maybe we only use random four points on the circle and to construct a quadrilateral?
    – Chonglin Zhu
    Dec 16 '18 at 15:48












    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
    Dec 16 '18 at 15:59




    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
    Dec 16 '18 at 15:59












    Thanks, this is very helpful!
    – Chonglin Zhu
    Dec 16 '18 at 16:00




    Thanks, this is very helpful!
    – Chonglin Zhu
    Dec 16 '18 at 16:00












    You're welcome!
    – Henrik Schumacher
    Dec 16 '18 at 16:00




    You're welcome!
    – Henrik Schumacher
    Dec 16 '18 at 16:00











    3














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

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


    enter image description here






    share|improve this answer




























      3














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

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


      enter image description here






      share|improve this answer


























        3












        3








        3






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

        SeedRandom[777]
        Graphics[{Circle,
        {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[{Circle,
        {Opacity[.5], EdgeForm[Gray], RandomColor, Polygon@#} & /@ randomQuad[5]}]


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 17 '18 at 0:15

























        answered Dec 16 '18 at 15:31









        kglrkglr

        177k9198408




        177k9198408























            3














            Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):



            n = 550;
            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}];
            disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
            shiftQuads = quads +
            RandomChoice[Flatten@disks, n]*
            Transpose[
            ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
            Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];

            {
            Opacity[.15],
            Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
            Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
            } // Graphics


            enter image description here






            share|improve this answer





















            • Great! I will have a try, so many thanks!
              – Chonglin Zhu
              Dec 18 '18 at 2:30
















            3














            Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):



            n = 550;
            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}];
            disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
            shiftQuads = quads +
            RandomChoice[Flatten@disks, n]*
            Transpose[
            ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
            Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];

            {
            Opacity[.15],
            Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
            Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
            } // Graphics


            enter image description here






            share|improve this answer





















            • Great! I will have a try, so many thanks!
              – Chonglin Zhu
              Dec 18 '18 at 2:30














            3












            3








            3






            Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):



            n = 550;
            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}];
            disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
            shiftQuads = quads +
            RandomChoice[Flatten@disks, n]*
            Transpose[
            ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
            Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];

            {
            Opacity[.15],
            Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
            Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
            } // Graphics


            enter image description here






            share|improve this answer












            Here's a fun way to use Henrik's stuff (and some other nicely vectorized operations):



            n = 550;
            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}];
            disks = {Range[2, 3], Range[7, 8] , Range[12, 15]};
            shiftQuads = quads +
            RandomChoice[Flatten@disks, n]*
            Transpose[
            ConstantArray[{Cos[Subdivide[0., 2. [Pi], n - 1]],
            Sin[Subdivide[0., 2. [Pi], n - 1]]}, 4], {2, 3, 1}];

            {
            Opacity[.15],
            Annulus[{0, 0}, {-1, 1} + MinMax@#] & /@ disks,
            Thread@{Opacity[.5], RandomColor[n], Thread[Polygon@shiftQuads]}
            } // Graphics


            enter image description here







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 17 '18 at 2:29









            b3m2a1b3m2a1

            26.9k257156




            26.9k257156












            • Great! I will have a try, so many thanks!
              – Chonglin Zhu
              Dec 18 '18 at 2:30


















            • Great! I will have a try, so many thanks!
              – Chonglin Zhu
              Dec 18 '18 at 2:30
















            Great! I will have a try, so many thanks!
            – Chonglin Zhu
            Dec 18 '18 at 2:30




            Great! I will have a try, so many thanks!
            – Chonglin Zhu
            Dec 18 '18 at 2:30


















            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

            Paul Cézanne

            UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

            Angular material date-picker (MatDatepicker) auto completes the date on focus out