Cylindrical half-pipe warp (inverse projection)

Mathematically generates a warp grid that simulates an inverse cylindrical projection, creating a 'half-pipe' visual effect where the image appears to curve into or out of the screen.

INPUT
INPUT — Cylindrical half-pipe warp (inverse projection)
OUTPUT
OUTPUT — Cylindrical half-pipe warp (inverse projection)
JavaScript
// Cylindrical half-pipe warp (inverse projection)
// warpgrid_halfpipe.js
//!INPUT: INPUT
//!OUTPUT: OUTPUT
//!PARAM: THETA_DEG:number=68,min=-360,max=360
//!PARAM: ROWS:integer=8,min=2,max=100
//!PARAM: COLS:integer=24,min=2,max=100

const thetaMax = THETA_DEG * Math.PI / 180;
const sinT = Math.sin(thetaMax);

const nodes = {};
for (let r = 0; r < ROWS; r++) {
    const row = [];
    for (let c = 0; c < COLS; c++) {
        const nc = c / (COLS - 1); // 0..1 horizontal
        const nr = r / (ROWS - 1); // 0..1 vertical

        // Inverse cylindrical projection for u (horizontal axis only)
        const u = (Math.asin((2 * nc - 1) * sinT) + thetaMax) / (2 * thetaMax);
        const v = nr; // cylinder axis is horizontal — no vertical distortion

        row.push(u, v);
    }
    nodes[String(r)] = row;
}

Engine.loadImage(INPUT)
    .warpGrid({ rows: ROWS, cols: COLS, nodes })
    .save(OUTPUT);

// © 2026 Michael Lechner · mlc OpticScript · https://mlcgo.eu · Elastic License 2.0