0

ポイントの座標を新しく生成されたシステム座標に転送しようとしています

元のシステムの元のポイントは左上隅にあります....

この質問pre_question
から取得したフォーマルを使用して いる座標を転送するために、次の関数を作成しました。 この質問には、意味と各部分の記号を示す 2 枚の写真があります。

今の問題は、 w の負の値を取得していることです! 誰でもこの機能をチェックして、どこに問題があるか教えてください

ありがとう

{

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 ; 

}

}

4

1 に答える 1

0

W 軸が X 軸に対応する場合、アフィン変換行列は M = [R]*[T] です。ここで、R はファイ角度による回転行列、T は x0、y0 による並進行列です。

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

T = 1  0  0
    0  1  0
    dx dy 1

これらの行列を乗算して M 行列を取得し、逆行列 MR = Inverse(M) を取得する必要があります。次に、M と MR を使用して座標を XY から WZ システムに、またはその逆に変換できます [xnew, ynew, 1] = [xold, yold, 1] * [M]

詳細はこちら

于 2013-04-18T02:47:07.453 に答える