PIXELBANKv9.1.0
Menu

Ray to Light Field Coordinates

Convert a 3D ray to light field (s, t, u, v) coordinates.

A light field parameterizes all rays in a scene using the two-plane representation:

  • (s,t)(s, t): intersection with the first plane (camera plane)
  • (u,v)(u, v): intersection with the second plane (focal plane)

Given a ray starting at origin (x0,y0,z0)(x_0, y_0, z_0) on the first plane (at z=0z=0) with direction (dx,dy,dz)(d_x, d_y, d_z), find where it intersects the second plane at z=zplanez = z_{plane}:

tparam=zplanedzt_{param} = \frac{z_{plane}}{d_z} u=x0+tparamâ‹…dxu = x_0 + t_{param} \cdot d_x v=y0+tparamâ‹…dyv = y_0 + t_{param} \cdot d_y

Example:

Input:
ray_to_lightfield([0, 0, 0], [0, 0, 1], 1)
Output:
(0, 0, 0, 0)
Reasoning:

Ray from origin pointing straight ahead: s, t = ray_origin[0:2] = (0, 0)

  • t_param = 1 / 1 = 1
  • u = 0 + 1 × 0 = 0
  • v = 0 + 1 × 0 = 0 Result: (0, 0, 0, 0) - ray goes through both plane centers.

Constraints:

  • ray_origin: [x, y, z] point on first plane (z=0)
  • ray_direction: [dx, dy, dz] direction vector
  • plane_distance: z-coordinate of second plane
  • Return (s, t, u, v) coordinates, rounded to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Ray to Light Field Coordinates - Medium | PixelBank