v9.1.1
Menu

Ray to Light Field Coordinates

mediumPROLight FieldsLight FieldCV: Image-Based Rendering

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
  • Inputs: ray_origin is the point (x0,y0,z0)=(0,0,0)(x_0, y_0, z_0) = (0, 0, 0) where the ray leaves the camera plane z=0z = 0. ray_direction is (dx,dy,dz)=(0,0,1)(d_x, d_y, d_z) = (0, 0, 1), pointing straight down the zz axis. plane_distance puts the focal plane at zplane=1z_{plane} = 1.
  • Camera plane: (s,t)(s, t) is just where the ray already sits on the first plane, so (s,t)=(x0,y0)=(0,0)(s, t) = (x_0, y_0) = (0, 0). The z0=0z_0 = 0 part carries no information.
  • Reaching the focal plane: the ray climbs dz=1d_z = 1 in zz per unit step, so it needs tparam=11=1t_{param} = \frac{1}{1} = 1 steps to reach z=1z = 1.
  • Focal plane: u=0+1⋅0=0u = 0 + 1 \cdot 0 = 0 and v=0+1⋅0=0v = 0 + 1 \cdot 0 = 0, rounded to 4 decimal places.
  • Output: (0, 0, 0.0, 0.0). The ray hits both planes at their centres.
  • Notice that (u−s,v−t)(u - s, v - t) encodes the ray's angle: a tilted direction like (1,1,1)(1, 1, 1) with the same origin lands at (u,v)=(1,1)(u, v) = (1, 1) instead.

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

Learn this in

More from CV: Image-Based Rendering

PRO

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

Sign in to run your code against the test cases.