title: OpenCV: Rotate points by an angle: Offset/shift in solution
body: <p>i am trying to rotate a set of points in a vector by an user-defined angle and found a solution at <a href="https://stackoverflow.com/questions/7953316/rotate-a-point-around-a-point-with-opencv">SO</a>.
  In the following code the dimension of the output image and the rotation angle (45 degree) is correct but the position of the points seem to be shifted. 
  Can someone give me a tip, what the problem is?
  edit: See attached pictures where the generated line is rotated correct, but the result does not begin at (0,0) (topleft).</p>
  
  <p><a href="https://i.stack.imgur.com/hXdiC.png" rel="nofollow noreferrer">generated Line</a>
  <a href="https://i.stack.imgur.com/P3jLi.png" rel="nofollow noreferrer">rotated Line</a></p>
  
  <pre><code>cv::Point rotate2d(const cv::Point&amp; inPoint, const double&amp; angRad)
  {
      cv::Point outPoint;
      //CW rotation
      outPoint.x = std::cos(angRad)*inPoint.x - std::sin(angRad)*inPoint.y;
      outPoint.y = std::sin(angRad)*inPoint.x + std::cos(angRad)*inPoint.y;
      return outPoint;
  }
  
  cv::Point rotatePoint(const cv::Point&amp; inPoint, const cv::Point&amp; center, const double&amp; angRad)
  {
      return rotate2d(inPoint - center, angRad) + center;
  }
  
  
  int main( int, char** argv )
  {
      // Create an dark Image with a gray line in the middle
      Mat img = Mat(83, 500, CV_8U);
      img = Scalar(0);
      vector&lt;Point&gt; pointsModel;
  
      for ( int i = 0; i&lt;500; i++)
      {
          pointsModel.push_back(Point(i , 41));
      }
  
      for ( int i=0; i&lt;pointsModel.size(); i++)
      {
          circle(img, pointsModel[i], 1, Scalar(120,120,120), 1, LINE_8, 0);
      }
      imshow("Points", img);
  
      // Rotate Points
      vector&lt;Point&gt; rotatedPoints;
      Point tmpPoint;
      cv::Point pt( img.cols/2.0, img.rows/2.0 );
      for ( int i=0; i&lt;pointsModel.size(); i++)
      {
          tmpPoint = rotatePoint(pointsModel[i] , pt , 0.7854);
          rotatedPoints.push_back(tmpPoint);
      }
      Rect bb = boundingRect(rotatedPoints);
      cout &lt;&lt; bb;
      Mat rotatedImg = Mat(bb.height, bb.width, img.type());
      rotatedImg = Scalar(0);
  
      for (int i=0; i&lt;rotatedPoints.size(); i++ )
      {
          circle(rotatedImg, rotatedPoints[i], 1, Scalar(120,120,120), 1, LINE_8, 0);
      }
      imshow("Points Rotated", rotatedImg);
      waitKey();
  
      return 0;
  }
  </code></pre>