Calculating rotation angle based on the applied transformation

6k Views Asked by At

I have got a quite complex problem. I have a particle simulation program, and i want to add solid objects to it, but still particle-based. for this, i want to deteermine the rotation the given transformation applies to my object. I have been trying to figure this out myself(couldnt find anything too much related to this)

heres what information i have:

  • Old point coordinates
  • New point coordinates
  • Speed on X and Y axis
  • Rotation center

I only need to calculate one points rotation angle(ill solve the rest) heres how far i got:

x' = x * cos( theta ) + y * -sin( theta );
y' = x * sin( theta ) + y * cos ( theta );

I need the value of theta. if possible I need to calculate this 1 million times / frame. If thats too much, then with some tweaking(accuracy lost) 1 000 - 50 000 times. Any other solution of the problem appreticiated. Could this be solved mathematically? If not, then is there some(even if inaccurate) way to solve this problem?

1

There are 1 best solutions below

0
On BEST ANSWER

Starting from :

$$ x' = x \cos\theta - y \sin\theta $$ $$ y' = x \sin \theta + y \cos \theta $$

Use this:

$$ \sin\theta = \frac{ y' x - x' y } {x^2+y^2 } $$ $$ \cos\theta = \frac{ x' x + y' y } {x^2+y^2 } $$

so

$$ \theta = \tan^{-1}\left( \frac{y' x - x' y}{x' x + y' y } \right) $$

To verify the results

$$ x' = x \cos\theta - y \sin\theta = x \left(\frac{ y' x - x' y } {x^2+y^2 }\right) - y \left( \frac{ x' x + y' y } {x^2+y^2 } \right) = $$ $$ = \frac{x ( x' x+y' y) - y (y' x-x' y) }{x^2+y^2} = \frac{ x' x^2 + x' y^2 }{x^2+y^2} = x' $$

and similarly for $$ y' = x \sin \theta + y \cos \theta = x \left( \frac{ x' x + y' y } {x^2+y^2 } \right) + y \left(\frac{ y' x - x' y } {x^2+y^2 }\right) = \ldots = y'$$