# Inverse 2D rotation with negative parameters

1. Dec 24, 2012

### atrus_ovis

1. The problem statement, all variables and given/known data
Say we have a 2D rigid body transform, with parameters $p = [ p_1,p_2,p_3]$ for rotation, x translation and y translation respectively.
I'm using the transform to .. transform an image.

Is there a way to have:
For a point x , y : x',y' = transform(x,y,p) <=> x,y = transform(x',y',-p) , meaning trasforming the transformed point with negative parameters of the initial transformation, gives us the initial point.
Expanding to the image, , i'd want for an image I:
I' = transform(I,p) <=> I = transform(I',-p)

This works simply for transforms that include only translations, but not for rotations.

The rotation is done by rotating the points by the center of ther image.
So by using a 2D rotation matrix with homogenous coordinates to include translation , i have to ,prior to rotation , translate the image by -cx,-cy where cx,cy are the coordinates of the image center , rotate , and then applying the translation.
By this way though , i'd have to know all prior transformations done to the image to know the (now changed) "location" of the image center.

So in short:
I have an image I', transformed by coordinates p.I want a transformation method to yield I when transforming I' with parameters -p.

Any ideas for this to work? Is it even possible?

2. Dec 24, 2012

### HallsofIvy

Staff Emeritus
I take it that p2 and p3 are the x and y translations but what is p1? The angle through which the figure rotated? But rotated about what point? The center? One corner?

Yes, translate the center of rotation to the origin, perform the rotation, then translate back again.

That is, taking $(x_0, y_0)$ as the center of rotation, you want to go through a list of points defining the figure, each being (x, y), translate to $(x- x_0, y- y_0)$, then rotate through angle $\theta$, using, perhaps, the matrix
$$\begin{bmatrix}cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta)\end{bmatrix}$$
then translate back, $(x+ x_0, y+ y_0)$.

3. Dec 24, 2012

### atrus_ovis

As i said, i rotate around the image center.
p1 is the rotation angle,p2 and p3 the x ,y translations respectively.

I am doing what you describe , but the problem is the following:
Say i have an image I', its center located at cx,cy, and it's transformed by p1,p2,p3.
(These parameters are unknown to me).
But by that transformation, the new image center ( that corresponds visually and logically to the initial image center) is now at cx + p2 , cy + p3.

If i use the same routine to apply a new transformation , i will rotate around cx,cy which is not the current image centre, but the initial one, so i wont get the initial image with parameters -p1 -p2 -p3.

A possible solution, is that i could have 2 routines, one for the "forward" transform that behaves the way you described, and one for the "backwards" transform, that firstly translates by -p2 -p3, and then applies the transformation. In that way, the image center will firstly get restored to its proper position and the rotation will be done "correctly".

But having two routines is undesirable.