Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-295

Apply Affine Matrix to Point

Problem

Apply a 2D affine transform to a point.

M is a 2x3 matrix storing the linear part and translation, and p = [x, y]. Return [M[0][0]*x + M[0][1]*y + M[0][2], M[1][0]*x + M[1][1]*y + M[1][2]].

Hint

The third column of M is the translation applied after the linear part.

Test cases

case 1
in: [[[1,0,0],[0,1,0]],[3,4]]
expected: [3,4]
case 2
in: [[[1,0,5],[0,1,-3]],[2,1]]
expected: [7,-2]
case 3
in: [[[0,-1,0],[1,0,0]],[1,0]]
expected: [0,1]
case 4
in: [[[2,0,1],[0,3,-2]],[2,1]]
expected: [5,1]
case 5
in: [[[1,0.5,0],[0,1,0]],[2,2]]
expected: [3,2]
Starter codePython
def apply_affine_matrix(M, p):
    # Your code here
    pass

5 test cases · run your code against them in the editor