Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:05:26+00:00 2026-06-13T01:05:26+00:00

I am using matrix.rotate method to rotate the rectangle (box in my case). My

  • 0

I am using matrix.rotate method to rotate the rectangle (box in my case).
My rotate event looks like below

public function transformObject(transformEvent:TransformEvent):void{

        var numChildrn:int = _markedObjectLayer.numChildren;
        var tempMatrix: Matrix = null;
        var tempx:Number;
        var tempy:Number;
        var tempHeight:Number;
        var tempWidth:Number;
        for(var i:int = 0; i < numChildrn; i++){
            var chld:MarkedObject = ObjectLayer.getChildAt(i)
            if (chld.selected){
                var  height:int = (BoxObject) chld.height;
                var  width:int = (BoxObject) chld.width;


                tempMatrix = chld.transform.matrix;


                tempHeight=height;  
                tempWidth=width;


                tempMatrix = MatrixTransformer.transform(tempMatrix,transformEvent.angle);


                tempMatrix.tx=tempx;
                tempMatrix.ty=tempy

                chld.transform.matrix = tempMatrix;
            }
        }

        invalidateDisplayList();
    }
} 

The Matrix.transform method calls matrix.rotate method

public static function transform(sourceMatrix:Matrix,
rotation:Number=0 ):Matrix
{

        sourceMatrix = MatrixTransformer.rotate(sourceMatrix, rotation, "degrees");

        return sourceMatrix;
    }



    /**
     * Rotates a matrix and returns the result. The unit parameter lets the user specify "degrees", 
     * "gradients", or "radians". 
     */
    public static function rotate(sourceMatrix:Matrix, angle:Number, unit:String = "radians"):Matrix {
        if (unit == "degrees") 
        {
            angle = Math.PI * 2 *( angle / 360);
        }

        sourceMatrix. rotate(angle)
        return sourceMatrix;
    }

The issue is that x and y are left corener of the box and hence it is rotating around left corner. However, if I try to give temp.x and temp.y as centroid value it does not rotate around centroid?

Can any one suggest what am I doing wrong here?

Thanks
Akshay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:05:27+00:00Added an answer on June 13, 2026 at 1:05 am

    Figured it out. It appears that I was not translating them to appropriate coordinate positions before and after rotation

    //Step 1 Fix the co-ordinates of rectangle . I added them to an event so that they remain static

        if (TransformEvent.X == 0 && TransformEvent.Y == 0)
            {
             TransformEvent.X = chld.x;
               TransformEvent.Y = chld.y;
             }
    

    //next get the centroid of rectangle

           tempx = TransformEvent.X + width/2;
           tempy= TransformEvent.Y +height/2;
    

    // Step 3: translate before rotation

            tempMatrix.translate(-1*tempx,-1*tempy);
    

    //Rotate the rectangle

            tempMatrix = MatrixTransformer.transform(tempMatrix,transformEvent.angle);
    

    //translate to centroid after rotation

             tempMatrix.translate(tempx,tempy);
    

    //assign back the matrix to the rectangle

             chld.transform.matrix = tempMatrix;
    

    Thanks for all your help. Also the this site helped me with translation bit
    http://www.foxarc.com/blog/article/66.htm

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like the following rotate(32) translate(0,-284.35468),translate(8545,84) matrix(d,f,g,s,g) translate(-58,88) Each function can
I am trying to rotate a rectangle using the matrix (x cos θ -
I am using glm::rotate to rotate a transformation matrix for a cube in a
I created a 2-D matrix using double pointer like that: int** pt; pt =
Here's the code i'm using to rotate: Dim m As New System.Drawing.Drawing2D.Matrix Dim size
Good evening. I'm trying to rotate a line on a canvas using setRotation -method
I have this 3x3 matrix which I'm using to preform basic transformations like translation,
I tried to rotate the bitmap using Matrix , its working fine if the
How can I rotate an Image eg. 180 degrees clockwise using the Matrix I
I have a style like this: .vertical-rotate{ filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.00000000, M12=-1.00000000, M21=1.00000000, M22=0.00000000,DX=32,sizingMethod='auto expand'); }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.