已知仿射變換的係數,求仿射變換的反向係數

對於以下從(xx,yy)到(X,Y)的仿射變換:code

X = xx + ax * xx + bx * yy + cx
Y = yy + ay * xx + by * yy + cyco

已知(ax,bx,cx),(ay,by,cy)爲其仿射變換系數,則(X,Y)到(xx,yy)必然也存在仿射變換關係:block

xx = X + axp* X + bxp * Y + cxp
yy = Y + ayp * X + byp * Y + cypreturn

求其對應的反向係數(axp,bxp,cxp),(ayp,byp,cyp)。printf

int main()
{   
    double ax = -0.00012457722524773310000000000;
    double bx = -0.00026952578840466643000000000;
    double cx = -40.53236981248609500000000000000;

    double ay = 0.00088450690917435935000000000;
    double by = -0.00006127575130507561900000000;
    double cy = -210.50907546352857000000000000000;

    double tt = ax * by + ax + by + 1 - bx * ay;

    double axp = (by+1) / tt - 1;
    double bxp = -bx / tt;
    double cxp = (bx * cy - cx - by * cx) / tt;
    double ayp = -ay / tt;
    double byp = (ax + 1) / tt - 1;
    double cyp = (ay * cx - cy - ax * cy) / tt;

    printf("%.10lf\t%.10lf\t%.10lf\n", axp, bxp, cxp);
    printf("%.10lf\t%.10lf\t%.10lf\n", ayp, byp, cyp);

    double xx = 500;
    double yy = 600;

    double X = xx + ax* xx + bx* yy + cx;
    double Y = yy + ay * xx + by * yy + cy;

    printf("原始:%.10lf\t%.10lf\n", xx, yy);
    printf("正運算:%.10lf\t%.10lf\n", X, Y);
    
    //axp = 0.00012480028850991864000000000;
    //bxp = 0.00026947569230899039000000000;
    //cxp = 40.47053059568900600000000000000;

    //ayp = -0.00088529760825697967000000000;
    //byp = 0.00006131347116844487700000000;
    //cyp = 210.73126518749581000000000000000;

    xx = X + axp* X + bxp * Y + cxp;
    yy = Y + ayp * X + byp * Y + cyp;
    printf("逆運算:%.10lf\t%.10lf\n", xx, yy); 

    return 0;
}
相關文章
相關標籤/搜索