ndcToPx

View sourcendcToPx(x: number, y: number, width?: number, height?: number): Vector2

Converts a normalized device coordinate (NDC) to a pixel-space coordinate.

Use this helper to map NDC coordinates into a viewport whose pixel origin is at the top left. NDC uses the center as (0, 0), X from -1 on the left to 1 on the right, and Y increasing upward. The returned pixel coordinate uses Y increasing downward. The inverse conversion is xPx = (x + 1) * width / 2 and yPx = (1 - y) * height / 2.

width and height default to the browser viewport’s innerWidth and innerHeight. The helper does not mutate its inputs and returns a new Vector2. Use pxToNdc for the inverse conversion.

Examples

const center = ndcToPx(0, 0, 800, 600)
// center.x === 400 and center.y === 300

Parameters

NameDescriptionDefault
x

NDC X coordinate, where -1 is left and 1 is right.

—
y

NDC Y coordinate, where -1 is bottom and 1 is top.

—
width?

Viewport width used for the conversion.

innerWidth
height?

Viewport height used for the conversion.

innerHeight

Returns

Pixel-space coordinate equivalent to the NDC coordinate, with origin at the top left.