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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:37:11+00:00 2026-06-01T02:37:11+00:00

I am doing some multi-touch support that allow 2 fingers to rotate a photos.

  • 0

I am doing some multi-touch support that allow 2 fingers to rotate a photos. There are four points: 2 for previous fingers and 2 for current finger positions.

I calculated a new point by subtract the 2 previous fingers, and the second new point was calculate by subtracting the other 2 current finger.

Then, I calculate the angle like this:

radian1 = atan ( p1.y / p1.x );
radian2 = atan ( p2.y / p2.x );

I subtract radian2 and radian1 to get the final angle.

The problem is I can rotate the image beautifully but sometime if I rotate to certain position the photo got flipped e.g. a photo supposed in 270 but it flipped and appeared in 90 degree.

This is the javascript I have written according to the reply below:

 var x1 = this.previousMousePoint.x * this.previousMousePoint2.x + this.previousMousePoint.y * this.previousMousePoint2.y;
var y1 = this.previousMousePoint.x * this.previousMousePoint2.y - this.previousMousePoint.y * this.previousMousePoint2.x;

var x2 = center.x * point.x + center.y * point.y;
var y2 = center.x * point.y - center.y * point.x;

var radian1 = Math.atan(y1 / x1);
var radian2 = Math.atan(y2 / x2);

this.anchor.matrix = this.anchor.matrix.rotate(radian2-radian1, pivot);

Is looking ok. but it’s kind of slow when i try to rotate an image

  • 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-01T02:37:12+00:00Added an answer on June 1, 2026 at 2:37 am

    The clean way to do this is use angle-subtraction formulas to get values proportional to the sine and cosine of the difference angle, and use atan() only once:

    relevant formulas:
      cos(a2 - a1) = cos(a1)*cos(a2) + sin(a1)*sin(a2)
      sin(a2 - a1) = cos(a1)*sin(a2) - sin(a1)*cos(a2)
    
      p1.x = cos(a1) * len(p1)
      p1.y = sin(a1) * len(p1)
    
      p2.x = cos(a2) * len(p2)
      p2.y = sin(a2) * len(p2)
    
    -> angle-subtraction: compute values proportional to sin and cos of (a2 - a1)
      c12 =  p1.x*p2.x + p1.y*p2.y   [ = len(p1)*len(p2) * cos(a2 - a1)  ]
      s12 =  p1.x*p2.y - p1.y*p2.x   [ = len(p1)*len(p2) * sin(a2 - a1)  ]
    
    -> final result:  find resulting difference angle a12 [ = a2 - a1  ]
      a12 = atan(s12 / c12)
    or (if you want a full 360-degree range):
      a12 = atan2(s12, c12)
    

    Also, if you want to rotate an image with the result, you may not need to convert (c12,s12) to an angle, anyway: ultimately, your image rotator will use a matrix with the sines and cosines of the resulting rotation angle. By normalizing (c12,s12), you will end up with (cos(a12), sin(a12)), which you may be able to use more directly.

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

Sidebar

Related Questions

I was just doing some random testing on locking in multi-threading this morning and
I'm doing some development work on a Magento site network (multi-store install). What I'm
While doing some refactoring I've found that I'm quite often using a pair or
I'm doing some multi-threading and use AutoResetEvents and ManualResetEvents do control my main -
We're in the process of doing some performance optimization for a multi-tenant Web application.
I have a multi-select Box and I'm doing some javascript to sort the order
I am currently looking at some code that is doing even trivial insert/select/update by
I must be doing some stupid mistake. I have a server that returns the
I'm looking for some input on my current project architecture. There are three components:
I'm doing some maintenance/evolution on a multi-layered spring 3.0 project. The client is a

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.