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\$
8
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.