7
\$\begingroup\$

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

enter image description here

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};
}
\$\endgroup\$
2

1 Answer 1

8
\$\begingroup\$

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.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .