Getting slice number of regular polygon from coordinates











up vote
0
down vote

favorite












For an n sided polygon divided up into n triangles, i want the triangle "index" from a coordinate inside the polygon



Example:



example



The coordinates at the green dot should give 2, the red dot should give 5 and the blue dot should give 3



Coordinate range is from 0 to diameter of the polygon



The polygon is not necessarily a 6 sided polygon










share|cite|improve this question
























  • Do you have freedom of scaling, rotation and choosing the origin?
    – Moti
    Nov 11 at 16:27










  • only scaling/radius @Moti
    – nobbele
    Nov 16 at 18:34










  • What you mean by give? Being inside the numbered region?
    – Moti
    Nov 16 at 21:32















up vote
0
down vote

favorite












For an n sided polygon divided up into n triangles, i want the triangle "index" from a coordinate inside the polygon



Example:



example



The coordinates at the green dot should give 2, the red dot should give 5 and the blue dot should give 3



Coordinate range is from 0 to diameter of the polygon



The polygon is not necessarily a 6 sided polygon










share|cite|improve this question
























  • Do you have freedom of scaling, rotation and choosing the origin?
    – Moti
    Nov 11 at 16:27










  • only scaling/radius @Moti
    – nobbele
    Nov 16 at 18:34










  • What you mean by give? Being inside the numbered region?
    – Moti
    Nov 16 at 21:32













up vote
0
down vote

favorite









up vote
0
down vote

favorite











For an n sided polygon divided up into n triangles, i want the triangle "index" from a coordinate inside the polygon



Example:



example



The coordinates at the green dot should give 2, the red dot should give 5 and the blue dot should give 3



Coordinate range is from 0 to diameter of the polygon



The polygon is not necessarily a 6 sided polygon










share|cite|improve this question















For an n sided polygon divided up into n triangles, i want the triangle "index" from a coordinate inside the polygon



Example:



example



The coordinates at the green dot should give 2, the red dot should give 5 and the blue dot should give 3



Coordinate range is from 0 to diameter of the polygon



The polygon is not necessarily a 6 sided polygon







geometry polygons






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Nov 11 at 14:44

























asked Nov 11 at 13:46









nobbele

12




12












  • Do you have freedom of scaling, rotation and choosing the origin?
    – Moti
    Nov 11 at 16:27










  • only scaling/radius @Moti
    – nobbele
    Nov 16 at 18:34










  • What you mean by give? Being inside the numbered region?
    – Moti
    Nov 16 at 21:32


















  • Do you have freedom of scaling, rotation and choosing the origin?
    – Moti
    Nov 11 at 16:27










  • only scaling/radius @Moti
    – nobbele
    Nov 16 at 18:34










  • What you mean by give? Being inside the numbered region?
    – Moti
    Nov 16 at 21:32
















Do you have freedom of scaling, rotation and choosing the origin?
– Moti
Nov 11 at 16:27




Do you have freedom of scaling, rotation and choosing the origin?
– Moti
Nov 11 at 16:27












only scaling/radius @Moti
– nobbele
Nov 16 at 18:34




only scaling/radius @Moti
– nobbele
Nov 16 at 18:34












What you mean by give? Being inside the numbered region?
– Moti
Nov 16 at 21:32




What you mean by give? Being inside the numbered region?
– Moti
Nov 16 at 21:32










1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Solved it using this(C# code but can probably be converted into math equation)



float arctan = Mathf.Atan(originRelativePos.x / originRelativePos.y);
float sectorDec = arctan / ((2 * Mathf.PI) / sectorCount);
float max = sectorCount / 4;

sectorDec = originRelativePos.x < 0 ? -sectorDec : sectorDec;
sectorDec = sectorDec > 0 ? sectorDec : max * 2 + sectorDec + 1;
sectorDec = originRelativePos.x < 0 ? sectorCount - sectorDec : sectorDec;

int sector = (int)sectorDec;


sector is the number of the sector, originRelativePos is position relative to the origin






share|cite|improve this answer





















    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: "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',
    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%2f2993895%2fgetting-slice-number-of-regular-polygon-from-coordinates%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Solved it using this(C# code but can probably be converted into math equation)



    float arctan = Mathf.Atan(originRelativePos.x / originRelativePos.y);
    float sectorDec = arctan / ((2 * Mathf.PI) / sectorCount);
    float max = sectorCount / 4;

    sectorDec = originRelativePos.x < 0 ? -sectorDec : sectorDec;
    sectorDec = sectorDec > 0 ? sectorDec : max * 2 + sectorDec + 1;
    sectorDec = originRelativePos.x < 0 ? sectorCount - sectorDec : sectorDec;

    int sector = (int)sectorDec;


    sector is the number of the sector, originRelativePos is position relative to the origin






    share|cite|improve this answer

























      up vote
      0
      down vote



      accepted










      Solved it using this(C# code but can probably be converted into math equation)



      float arctan = Mathf.Atan(originRelativePos.x / originRelativePos.y);
      float sectorDec = arctan / ((2 * Mathf.PI) / sectorCount);
      float max = sectorCount / 4;

      sectorDec = originRelativePos.x < 0 ? -sectorDec : sectorDec;
      sectorDec = sectorDec > 0 ? sectorDec : max * 2 + sectorDec + 1;
      sectorDec = originRelativePos.x < 0 ? sectorCount - sectorDec : sectorDec;

      int sector = (int)sectorDec;


      sector is the number of the sector, originRelativePos is position relative to the origin






      share|cite|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Solved it using this(C# code but can probably be converted into math equation)



        float arctan = Mathf.Atan(originRelativePos.x / originRelativePos.y);
        float sectorDec = arctan / ((2 * Mathf.PI) / sectorCount);
        float max = sectorCount / 4;

        sectorDec = originRelativePos.x < 0 ? -sectorDec : sectorDec;
        sectorDec = sectorDec > 0 ? sectorDec : max * 2 + sectorDec + 1;
        sectorDec = originRelativePos.x < 0 ? sectorCount - sectorDec : sectorDec;

        int sector = (int)sectorDec;


        sector is the number of the sector, originRelativePos is position relative to the origin






        share|cite|improve this answer












        Solved it using this(C# code but can probably be converted into math equation)



        float arctan = Mathf.Atan(originRelativePos.x / originRelativePos.y);
        float sectorDec = arctan / ((2 * Mathf.PI) / sectorCount);
        float max = sectorCount / 4;

        sectorDec = originRelativePos.x < 0 ? -sectorDec : sectorDec;
        sectorDec = sectorDec > 0 ? sectorDec : max * 2 + sectorDec + 1;
        sectorDec = originRelativePos.x < 0 ? sectorCount - sectorDec : sectorDec;

        int sector = (int)sectorDec;


        sector is the number of the sector, originRelativePos is position relative to the origin







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered Nov 16 at 22:44









        nobbele

        12




        12






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2993895%2fgetting-slice-number-of-regular-polygon-from-coordinates%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