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 966825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:13:14+00:00 2026-05-16T02:13:14+00:00

I am basically trying to create a display object transformation manager which will allow

  • 0

I am basically trying to create a display object transformation manager which will allow me to scale/rotate objects. I am currently trying to figure out how to rotate an object so its corner follows the current x and y of the mouse.

Example 1

Example 2

Example 3

I always get confused on the math of things like this. I know how to listen for the events and everything, I just am unsure of how to calculate the amount of rotation to apply. I will probably be rotating via a Matrix so I can rotate the object around its center, rather than the upper-left corner of it. Can anyone who is more skilled with the math of this help me out?

IN RESPONSE TO TROBADOUR

Your answer is so brilliant that I can’t understand it at all. Let me explain what I can grasp and what I can’t. Here’s a walkthrough of what I do/don’t understand:

First, save what will be the middle of the image, the so-called registration point around which we will rotate everything:

var box:Sprite = new BeautifulSprite();
box.width = box.height = 100;
/* ... */
var registrationPoint:Point = new Point(box.x + box.width / 2, 
        box.y + box.height / 2);

Am I correct so far? If so, I’ll continue.

Second, denote the original mouse-down position:

var mouseDownPoint:Point = new Point(box.mouseX, box.mouseY);

Third, store the “vector.” Problem is, I’m not sure of what you mean vector. I am familiar with Vector types in Java and AS3, in that they store a list of values of a certain type. Beyond that, I’m lost.

var vector:* = WTF.forReals();

Next, save the distance between registrationPoint and mouseDownPoint. I remember learning about calculating distance between two points way back in high school, so I’m sure I could dig up the formula for distance between two 2d points.

var distance:Number = calculateDistance(registrationPoint, mouseDownPoint);

I know I’m getting close! Next, to determine the constrained scale, we get the current mouse location, determine its distance to registrationPoint, and divide that by distance.

var constrainedScale:Number = calculateDistance(registrationPoint, new Point(mouseX, mouseY)) / distance;

My question here is: how do I get values when I don’t want them constrained, like scaleX and scaleY?

Now, to get the actual rotation around the registration point, I am completely lost. Could you help me out, using the variables I have defined above?

  • 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-05-16T02:13:15+00:00Added an answer on May 16, 2026 at 2:13 am

    Denote the mouse co-ords of the scale/rotation centre as (x0,y0) and the mouse co-ords of the corner when in an unscaled, unrotated state as (x1,y1). Store the point (x0,y0) and cache both the vector and the distance between (x0,y0) and (x1,y1). Denote the cached vector by v0 and the distance by d0.

    To get the scale factor just compute the current mouse co-ords distance to (x0,y0) and divide that by d0.

    To get the rotation angle first calculate the vector between (x0,y0) and the current mouse co-ords. Denote this by v. Then calculate the angle by using the dot product formula

    v.v0 = |v| d0 cos(theta)

    which will give you something between 0 and pi. To get into the correct quadrant just examine the sign of the cross product of v and v0 and adjust accordingly.

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

Sidebar

Related Questions

Basically I am trying to create a little program that will allow me to
I'm trying to create a web page that will display an appropriate user control
I am trying to create pager which will sit in the center of the
I'm trying to create a UITable in which the cells display some text and,
I'm basically trying to create a url friendly query string with user input. The
I'm basically trying to create a 2 column div with a liquid <h1> and
im stuck with a problem im basically trying to create a function where I
Basically I'm trying to create a BASIC sorting program in ruby without using .sort
Basically I'm trying to create an implementation of simulated annealing for the multidimensional knapsack
I am trying to create something in Perl that is basically like the Unix

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.