# 传递函数中的坐标误差transfer the co-ordinates error in function

{

``````CvPoint transfer_coordinate (CvPoint pt1 , CvPoint pt2 , CvPoint pt3 , CvPoint pt4 , CvPoint origin , CvPoint current)
{
// pt1 , pt2 ==> points in line Z
// pt3 , pt4 ==> points in line W
double a1 , a2 , b1 , b2 , d1 , d2;

d1= sqrt(pow((pt1.x - pt2.x),2.0)+ pow((pt1.y - pt2.y),2.0));
d2= sqrt(pow((pt3.x - pt4.x),2.0)+ pow((pt3.y - pt4.y),2.0));

a1 =(pt1.y-pt2.y)/d1;
b1 =(pt2.x-pt1.x)/d1;

a2 =(pt3.y-pt4.y)/d2;
b2 =(pt4.x-pt3.x)/d2;

CvPoint new_point;
//z = -sqrt(a1^2+b1^2)*(a2*(x-x0)+b2*(y-y0))/(a2*b1-a1*b2)
//w =  sqrt(a2^2+b2^2)*(a1*(x-x0)+b1*(y-y0))/(a1*b2-a2*b1)
//z
new_point.x = -round(sqrt(pow(a1,2.0)+ pow(b1,2.0)) * (a2 * (current.x - origin.x) + b2 * (current.y - origin.y))/(a2 * b1 - a1 * b2));
// w
new_point.y = round(sqrt(pow(a2,2.0)+ pow(b2,2.0)) * (a1 * (current.x - origin.x) + b1 * (current.y - origin.y))/(a1 * b2 - a2 * b1));

CvPoint reverse_point;
//x = x0 - b1*z/sqrt(a1^2+b1^2) + b2*w/sqrt(a2^2+b2^2)
//y = y0 + a1*z/sqrt(a1^2+b1^2) - a2*w/sqrt(a2^2+b2^2)
//x
reverse_point.x = round (origin.x - b1 * new_point.x / sqrt(pow(a1,2.0) + pow(b1,2.0)) + b2 * new_point.y /sqrt(pow(a2,2)+ pow(b2,2)));
//y
reverse_point.y = round (origin.y + a1 * new_point.x / sqrt(pow(a1,2.0) + pow(b1,2.0)) - a2 * new_point.y /sqrt(pow(a2,2)+ pow(b2,2)));

//printf("\n points in Z line (%d,%d),(%d,%d) , points in W line (%d,%d),(%d,%d) , origin (%d,%d)",pt1.x,pt1.y,pt2.x,pt2.y,pt3.x,pt3.y,pt4.x,pt4.y,origin.x,origin.y);
//printf("\n current point = (%d,%d) , new point = (%d,%d) , reverse point = (%d,%d)" , current.x,current.y,new_point.x,new_point.y,reverse_point.x,reverse_point.y);

return new_point ;
``````

}

}

## 1 个回复1

### ===============>>#1 票数：0

``````R = Cos(phi) -Sin(phi) 0
Sin(phi)  Cos(phi) 0
0         0       1
``````

``````T = 1  0  0
0  1  0
dx dy 1
``````