# Get local coords from global coords

I need to get local coords from global coords. I did not find ready-made examples.

## 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. Nov 15 '15 at 1:34
• Nov 15 '15 at 3:02

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

$$\begin{pmatrix} 50 \\ 40 \\ 1 \end{pmatrix}$$

The homogeneous transformation matrix M is (using $$\cos(\frac{\pi}{4}\$$) = sin($$\\frac{\pi}{4}) = 0.7071)\$$:

$$\begin{pmatrix} 0.7071 &0.7071 &-42.426 \\ -0.7071 &0.7071 &14.142 \\ 0 &0 & 1 \\ \end{pmatrix}$$

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

$$\begin{pmatrix} 35.35 &+ &28.28 &- &42.42 \\ -35.35 &+ &28.28 &+ &14.14 \\ 0 &+ &0 &+ &1 \\ \end{pmatrix}= \begin{pmatrix} 21.21 \\ 7.07 \\ 1 \\ \end{pmatrix}$$

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.