{"id":141,"date":"2009-01-01T00:00:49","date_gmt":"2009-01-01T07:00:49","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=446"},"modified":"2009-01-01T00:00:49","modified_gmt":"2009-01-01T07:00:49","slug":"matrixtransformpoint","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=141","title":{"rendered":"Matrix.transformPoint()"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar circle:Shape = Shape(addChild(new Shape()));\r\nwith(circle.graphics) beginFill(0x00000), drawCircle(0,0,10);\r\n\r\nvar point:Point = new Point();\r\nvar trans:Matrix = new Matrix();\r\ntrans.rotate(Math.PI);\r\ntrans.scale(.5, .5);\r\ntrans.tx = stage.stageWidth \/ 2;\r\ntrans.ty = stage.stageHeight \/ 2;\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\n\r\nfunction onLoop(evt:Event):void {\r\n\tpoint.x = mouseX - trans.tx;\r\n\tpoint.y = mouseY - trans.ty;\r\n\t\r\n\tpoint = trans.transformPoint(point);\r\n\t\r\n\tcircle.x = point.x;\r\n\tcircle.y = point.y;\r\n}\r\n<\/pre>\n<p>If you don&#8217;t feel like rolling your own transformations Matrix.transformPoint() is a very powerful method. It simply applies the tranformations of a given matrix to a Point. The above example scales rotates and translates a point which is then used to position a circle Shape.<\/p>\n<p>Matrix.transformPoint() is well suited for creating orbiting behavior:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar circle:Shape = Shape(addChild(new Shape()));\r\nwith(circle.graphics) beginFill(0x00000), drawCircle(0,0,10);\r\n\r\nvar point:Point = new Point(100,0);\r\nvar trans:Matrix = new Matrix();\r\n trans.rotate(.1);\r\n trans.scale(.99,.99);\r\n\r\naddEventListener(Event.ENTER_FRAME, onLoop);\r\n\r\nfunction onLoop(evt:Event):void {\r\n\t \r\n      point = trans.transformPoint(point);\r\n\t \r\n      circle.x = point.x + stage.stageWidth \/ 2;\r\n      circle.y = point.y + stage.stageHeight \/ 2;\r\n}\r\n<\/pre>\n<p>This code will cause the circle Shape to move in a spiral formation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var circle:Shape = Shape(addChild(new Shape())); with(circle.graphics) beginFill(0x00000), drawCircle(0,0,10); var point:Point = new Point(); var trans:Matrix = new Matrix(); trans.rotate(Math.PI); trans.scale(.5, .5); trans.tx = stage.stageWidth \/ 2; trans.ty = stage.stageHeight \/ 2; addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { point.x = mouseX &#8211; trans.tx; point.y = mouseY &#8211; trans.ty; point = trans.transformPoint(point); circle.x = point.x; circle.y = point.y; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94,13],"tags":[3,4,107],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-misc","category-motion","tag-actionscript","tag-flash","tag-matrix"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=141"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}