All problems
Projection Matrix onto Plane
Problem
Build the 3x3 matrix that projects onto the plane through the origin with normal n:
P = I - (n n^T) / (n . n)
Return None if n is the zero vector. P is symmetric, idempotent, and maps n to zero.
Hint
Subtract from the identity the rank-1 matrix that projects onto the normal.
Test cases
case 1
in: [[0,0,1]]
expected: [[1,0,0],[0,1,0],[0,0,0]]
case 2
in: [[0,0,2]]
expected: [[1,0,0],[0,1,0],[0,0,0]]
case 3
in: [[1,1,1]]
expected: [[0.6666666666666667,-0.3333333333333333,-0.3333333333333333],[-0.3333333333333333,0.6666666666666667,-0.3333333333333333],[-0.3333333333333333,-0.3333333333333…
case 4
in: [[1,0,0]]
expected: [[0,0,0],[0,1,0],[0,0,1]]
case 5
in: [[0,0,0]]
expected: null
Starter codePython
def projection_matrix_plane(n):
# Your code here
pass5 test cases · run your code against them in the editor