warpvas
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
26 lines (25 loc) • 861 B
TypeScript
/**
* Compute 2D affine transformation matrix from three point pairs
*
* @param newCoords - Transformed coordinates triad [Coord, Coord, Coord]
* @param oldCoords - Original coordinates triad [Coord, Coord, Coord]
*
* @returns Matrix parameters [a, b, c, d, e, f] for equation:
* X = ax + cy + e
* Y = bx + dy + f
*
* @example
* ```typescript
* // Calculate 45-degree rotation matrix
* const matrix = calcMatrix(
* [{x:0,y:0}, {x:0.707,y:0.707}, {x:-0.707,y:0.707}],
* [{x:0,y:0}, {x:1,y:0}, {x:0,y:1}]
* ); // ≈ [0.707, 0.707, -0.707, 0.707, 0, 0]
* ```
*
* @remarks
* - Points must be non-collinear in both sets
* - Input order must correspond between sets
* - Includes safeFactor adjustment for zero values
*/
export declare const calcMatrix: (newCoords: [Coord, Coord, Coord], oldCoords: [Coord, Coord, Coord]) => number[];