math - transfer the co-ordinates error in function -


i trying transfer coordinates of points new generated system coordinates

the original points in original system in top left corner ....

i wrote following function transfer coordinates
using formal got question pre_question question has 2 photos show mean , sign each part

the problem , getting negative value w ! can please check function , let me know problem

thanks

{

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 ;  

}

}

if w-axis corresponds x-axis, affine transformation matrix m = [r]*[t], r rotation matrix phi angle , t translation matrix x0, y0

r = cos(phi) -sin(phi) 0     sin(phi)  cos(phi) 0     0         0       1 

and

t = 1  0  0     0  1  0     dx dy 1 

you have multiply these matrices m matrix , inverse matrix mr = inverse(m). can use m , mr transform coordinates xy wz system , vice versa [xnew, ynew, 1] = [xold, yold, 1] * [m]

more information here


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -