嗨,我正在尝试创建仿射变换,这将允许我将三角形转换为另一个.我所拥有的是2个三角形的坐标.你能帮助我吗?
按照亚当罗森菲尔德的回答,我想出了这个代码,万一有人无聊自己解决方程:
public static AffineTransform createTransform(ThreePointSystem source,
ThreePointSystem dest) {
double x11 = source.point1.getX();
double x12 = source.point1.getY();
double x21 = source.point2.getX();
double x22 = source.point2.getY();
double x31 = source.point3.getX();
double x32 = source.point3.getY();
double y11 = dest.point1.getX();
double y12 = dest.point1.getY();
double y21 = dest.point2.getX();
double y22 = dest.point2.getY();
double y31 = dest.point3.getX();
double y32 = dest.point3.getY();
double a1 = ((y11-y21)*(x12-x32)-(y11-y31)*(x12-x22))/
((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22));
double a2 = ((y11-y21)*(x11-x31)-(y11-y31)*(x11-x21))/
((x12-x22)*(x11-x31)-(x12-x32)*(x11-x21));
double a3 = y11-a1*x11-a2*x12;
double a4 = ((y12-y22)*(x12-x32)-(y12-y32)*(x12-x22))/
((x11-x21)*(x12-x32)-(x11-x31)*(x12-x22));
double a5 = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Kloss和Kloss在“使用NumPy进行N维线性向量场回归”(2010,Python论文源代码2)中给出的解决方案,给出给定两点的二维仿射变换。
他们提供了一种方法来查找连接两组点y和x的仿射变换, 其中该变换由矩阵A和向量b表示(即矩阵方程y = Ax + b)。
在二维中,您有6个未知数,其中四个定义2x2 A矩阵,另外2个定义b。
但是,在示例脚本和描述它的论文中,它们具有未知数t = n ^ 2 + n,其中n是点的数量,这意味着您需要六个点,对于2D情况,它实际上是12个已知值(即x和图像上每个点的y值)。
他们通过以下方式对此进行了测试:
def solve(point_list):
"""
This function solves the linear equation system involved in the n
dimensional linear extrapolation of a vector field to an arbitrary point.
f(x) = x * A + b
with:
A - The "slope" of the affine function in an n …Run Code Online (Sandbox Code Playgroud)