如果您将点和变换插入 Maple,您可以很快得到结果。
> with(LinearAlgebra);
> # The server coordinates
pa := [[96.629539, 217.31934], [97.289948, 167.21941], [145.69249, 168.28044],
[145.69638, 219.84604]]:
> # The local coordiantes
pb := [[126.0098, 55.600437], [262.39163, 53.98035], [259.41382, 195.34763],
[121.48138, 184.95235]]:
> # The placeholder variables for the transformation (last one is '1', because it
# is scale-invariant)
T := [seq]([seq](`if`(i = 3 and j = 3, 1, t[i, j]), j = 1 .. 3), i = 1 .. 3):
V := convert(map(op, T)[1 .. -2], set):
> # Transformation function (Matrix multiplication + divide with 3rd coordinate)
trans := (p, T) -> [
(T[1, 1]*p[1]+T[1, 2]*p[2]+T[1, 3])/(T[3, 1]*p[1]+T[3, 2]*p[2]+T[3, 3]),
(T[2, 1]*p[1]+T[2, 2]*p[2]+T[2, 3])/(T[3, 1]*p[1]+T[3, 2]*p[2]+T[3, 3])
]:
> # Transform pa, and construct the equation system
pat := map(trans, pa, T):
eqs := {op}(zip((p1, p2) -> op(zip(`=`, p1, p2)), pat, pb)):
> # Solve for the transform variables
sol := solve(eqs, V):
> # Populate the transform
eval(T, sol);
输出:
[[ .1076044020, -3.957029830, 1074.517140 ],
[ 4.795375318, .3064507355, -430.7044862 ],
[ 0.3875626264e-3, 0.3441632491e-2, 1 ]]
要使用它,请将它与服务器点相乘作为T * <x, y, 1>
.
void ServerToLocal(double serverX, double serverY, double *localX, double *localY)
{
double w;
w = 0.3875626264e-3 * serverX + 0.3441632491e-2 * serverY + 1.0;
*localX = (.1076044020 * serverX - 3.957029830 * serverY + 1074.517140) / w;
*localY = (4.795375318 * serverX + .3064507355 * serverY - 430.7044862) / w;
}
另一种方法可以在 http://alumni.media.mit.edu/~cwren/interpolator/阅读
给定一个合理的线性代数库,这个可以用 C 语言编写。