# Get local coords from global coords

I need to get local coords from global coords. I did not find ready-made examples. Please help me how to do it on the example image. Thank you!

## UPDATED:

Here's the method in the java, created thanks to your help! It works for me :) Thank you!

public static double[] getLocalFromGlobal(int pointX, int pointY, int localX, int localY, float angle) {
float px = pointX - localX;
float py = pointY - localY;

double cos = Math.cos((Math.PI / 180) * angle);
double sin = Math.sin((Math.PI / 180) * angle);

double finalX = (px * cos) + (py * sin);
double finalY = -(px * sin) + (py * cos);
return new double[]{finalX, finalY};
}

• Use a Homogenous Transformation Matrix with R = a CW rotation by 45 degrees and T = a translation by (40,20). If you need the inverse, use the inverses. – Pieter Geerkens Nov 15 '15 at 1:34
• – Pieter Geerkens Nov 15 '15 at 3:02

## 1 Answer

The point P to be transformed is, in homogenous coordinates:

( 50 )
( 40 )
(  1 )


The homogenous transformation matrix M is (using cos(pi/4) = sin(pi/4) = 0.7071):

( 0.7071  0.7071  -42.426 )
(-0.7071  0.7071   14.142 )
( 0       0         1     )


noting that (40+20) * 0.7071 = 42.426 and (40-20) * 0.7071 = 14.142 and using the identity proved in my answer here

Applying M to P with matrix multiplication yields

( 35.35 + 28.28 - 42.42 )   ( 21.21 }
(-35.35 + 28.28 + 14.14 ) = (  7.07 )
(  0    +  0    +  1    )   (  1    )


Update:

Note that normal vectors, such as for position and velocity, are contra-variant; this means that for a transformation T of the basis vectors, the components transform by the inverse transformation, T*. Only dual vectors such as gradient are co-variant, with their components transforming by T.