# Apply transformation to a Vector2

I need a method for my java game that transforms a 2D vector normal by a matrix.
I have basic knowledge about matrices.

Someone explained the method as following:

TransformNormal() used for direction, tangent vectors. This reserves the matrix.
In Math: retVect = srcVec x M.

Vector2.TransformNormal() only applies the Scale and Rotational parts of the Matrix to the vector.

I do not fully understand this.

Vector2.TransformNormal() only applies the Scale and Rotational parts of the Matrix to the vector.

A normal is a direction vector so it does not require a displacement, ie 2 parallel planes have the same normal.

I am not sure why you need normals in a 2d game. They are mostly used for lighing in 3D.

It is used in a pixel perfect collision method with support of rotated images.

Do you know the formula to apply a matrix’s scale and rotational parts to a vector2?

If you are translating your points in 2D with a matrix as well as rotating them, you will need a 3x3 matrix, where the points you transform require an extra term w which equals 1:

``````[x,y,1] * M = [x', y', 1]
``````

If you only have uniform scaling (or no scaling), then for vectors such as normals you can use the same matrix you used to transform the points but set the w term equal to 0 which will ignore the translation:

``````[nx, ny, 0] * M = [nx', ny', 0]
``````

However, if you have non-uniform scaling then you need to use the inverse transpose to transform the normals:

``````[nx, ny, 0] * transpose(inverse(M)) = [nx', ny', 0]
``````

Thank you for the help. Unfortunately I did not fully understand your formulas.

I have a 3x3 Matrix like this.
And I have a Vector2, holding x and y.

I want to apply the Scale and Rotational parts of the Matrix to the vector.

If you have no scaling (or only uniform scaling), then just multiply [x, y, 0] by the 3x3 matrix. If you have scaling, you will need to first invert the matrix, then transpose it, then multiple [x, y, 0] by it.

See if this helps
http://www.cs.trinity.edu/~jhowland/cs2322/2d/2d/

Thanks! I think I can solve this now.