Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-297

Project Vector onto Plane

Problem

Project vector v onto the plane through the origin with normal n.

Remove the component along the normal:

v - ((v . n) / (n . n)) * n

Return None if n is the zero vector.

Hint

Subtract the projection onto the normal; the normal direction is the only one removed.

Test cases

case 1
in: [[1,2,3],[0,0,1]]
expected: [1,2,0]
case 2
in: [[2,3,4],[1,1,1]]
expected: [-1,0,1]
case 3
in: [[1,-1,5],[1,1,0]]
expected: [1,-1,5]
case 4
in: [[1,2,3],[0,0,0]]
expected: null
case 5
in: [[1,1,1],[0,0,2]]
expected: [1,1,0]
Starter codePython
def project_onto_plane(v, n):
    # Your code here
    pass

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