Surface Normal from Two Tangents

~12 mincode completion

Implement surface_normal(dP_dx, dP_dy) on two length-3 vectors and return the unit normal.

Examples

The xy-plane has normal +z

Input
surface_normal([1, 0, 0], [0, 1, 0])
Output
[0, 0, 1]

A shear in z tilts the normal in the xz plane

Input
surface_normal([1, 0, 1], [0, 1, 0])
Output
[-0.70711, 0, 0.70711]

Scaling both tangents does not change the unit normal

Input
surface_normal([2, 0, 0], [0, 3, 0])
Output
[0, 0, 1]

Hints

Hint 1

gives the magnitude in one call; pick the axis deliberately.

Hint 2

A common slip here: added the tangents instead of crossing them.

Requirements

  • Return length-3 unit vector

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

8 employers weight this skill

4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 93.

Python
import numpy as np


def surface_normal(dP_dx, dP_dy):
    """
    Unit normal from two surface-tangent vectors.

    Args:
        dP_dx, dP_dy: length-3 arrays

    Returns:
        length-3 unit vector
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.