I’m trying to get the coordinates of the center of a rotated item and to calculate them I need the width and height…

I’m trying to get the coordinates of the center of a rotated item and to calculate them I need the width and height of the box of the item, but there is no string for this in the API. Item.getWidth and getHeight don’t work because the item is rotated. Am I missing something here or is there just no way the can be done easily.

]]>

6 Commentsto I’m trying to get the coordinates of the center of a rotated item and to calculate them I need the width and height…

  1. Anonymous says:

    < ![CDATA[

    function center(item){


        var r=item.getRotation()*Math.PI/180;


        var sin=Math.abs(Math.sin(r));


        var cos=Math.abs(Math.cos(r));


        var w=item.getWidth()*item.getScaleX();


        var h=item.getHeight()*item.getScaleY();


        return[item.getPositionX()+(w*cos+h*sin)*0.5,item.getPositionY()+(h*cos+w*sin)*0.5];


    }



    (Copy-paste from http://www.pierrox.net/android/applications/lightning_launcher/wiki/doku.php?id=script_multitool)

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Wow thanks for the fast response! I hadn’t looked there.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Ah, memories 🙂

    ]]>

  4. Anonymous says:

    < ![CDATA[

    TrianguloY  I don’t even know what it’s for in the multitool script XD. Soo long ago 😉

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Well, it is a ‘tool’ 😛

    ]]>

  6. Anonymous says:

    < ![CDATA[

    TrianguloY


    just searched through: It’s just displayed as information.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *