soknaly

Calculate Rotation Degree between Two Points

Nov 9th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. static double cosBetweenTwoVector(Point vec1,Point vec2){
  2.     float divider = sqrt(pow(abs(vec1.x), 2)+ pow(abs(vec1.y),2)) * sqrt(pow(abs(vec2.x), 2) + pow(abs(vec2.y), 2));
  3.     float cosin = (vec1.x*vec2.x)+(vec1.y*vec2.y)/ divider;
  4.     return cosin;
  5. }
  6.           Point vec1 = Point(p1.x-p2.x,p1.y-p2.y);
  7.           Point vec2 = Point(0,vec1.y);
  8.           cout<< "Cosin= " << cosBetweenTwoVector(Point(0,3),Point(0,3));
  9.           float rotationRadius = acos(cosBetweenTwoVector(vec1, vec2));
  10.           float RAD2DEG = 180 / M_PI;
  11.           float rotationDeg = rotationRadius * RAD2DEG;
  12.           if (rotationDeg < 80 || rotationDeg > 100) {
  13.              rotateImage(src, 90-rotationDeg, src);
  14.           }
  15.           cout<< "Rotatation: " << rotationDeg << endl;
Advertisement
Add Comment
Please, Sign In to add comment