Skip to main content
100%

Perspective Transformation

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Apr 13, 2014

A sailboat image is perspective-transformed onto a mosque background, with draggable corner handles adjusting the projection in real time. The image and a grid of lines are rendered in SVG, while the transform is applied via a CSS `matrix3d` style. The matrix is computed by solving linear equations from four point-pairs using LU decomposition from numeric.js, with `d3.behavior.drag` handling handle movement and preset buttons animating transitions.

AI-generated description

A perspective projection can be precisely specified through four pairs of corresponding points. By dragging the four corners of the sailboat image above, you can adjust the perspective projection interactively and place the image anywhere you like in the scene.

The image is transformed using a matrix3d CSS transform. The transformation matrix is computed by solving a series of linear equations derived from the four point-pairs using LU decomposition as implemented by numeric.js.

This technique can also be used to apply a perspective transform manually for simple 2D shapes, such as lines and circles.

gpl-3.0 Licensed

Similar vizzes