Skip to content

Commit 1daf11e

Browse files
committed
Adding a coordinate remapping function.
1 parent feda7dd commit 1daf11e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Numerical algorithms for computational mathematics.
4343

4444
Common linear algebra algorithms for dealing with matrices and vectors. In all functions, _vectors_ are considered to be 1D arrays while _matrices_ are 2D arrays (i.e. arrays of arrays).
4545

46+
* [`_coordinate_remap`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_coordinate_remap/_coordinate_remap.gml): Remaps a coordinate from one rectangular region to another.
4647
* [`_linear_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_linear_solve/_linear_solve.gml): Solves a linear system of the form _Ax = b_ (using [Gaussian elimination with partial pivoting](https://en.wikipedia.org/wiki/Pivot_element)).
4748
* [`_matrix_multiply`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_multiply/_matrix_multiply.gml): Performs matrix-matrix, matrix-vector, and vector-vector multiplication.
4849
* [`_matrix_transpose`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_transpose/_matrix_transpose.gml): Transposes a 2D matrix.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// @func _coordinate_remap(xi1, yi1, xi2, yi2, xf1, yf1, xf1, yf2, x, y)
2+
/// @desc Remaps a coordinate from one rectangular region to another.
3+
/// @param {real} xi1 Initial rectangular region's minimum x-value.
4+
/// @param {real} yi1 Initial rectangular region's minimum y-value.
5+
/// @param {real} xi2 Initial rectangular region's maximum x-value.
6+
/// @param {real} yi2 Initial rectangular region's maximum y-value.
7+
/// @param {real} xf1 Final rectangular region's minimum x-value.
8+
/// @param {real} yf1 Final rectangular region's minimum y-value.
9+
/// @param {real} xf2 Final rectangular region's maximum x-value.
10+
/// @param {real} yf2 Final rectangular region's maximum y-value.
11+
/// @param {real} x x-coordinate to be remapped.
12+
/// @param {real} y y-coordinate to be remapped.
13+
/// @return {real[]} Remapped coordinates of input point, as an ordered pair [x, y].
14+
15+
function _coordinate_remap(xi1, yi1, xi2, yi2, xf1, yf1, xf2, yf2, xx, yy)
16+
{
17+
// Calculate remapped coordinates
18+
var xf, yf;
19+
xf = ((xx - xi1)*(xf2 - xf1))/(xi2 - xi1) + xf1;
20+
yf = ((yy - yi1)*(yf2 - yf1))/(yi2 - yi1) + yf1;
21+
22+
return [xf, yf];
23+
}

0 commit comments

Comments
 (0)