0

I have a polyline figure, given as an array of relative x and y point coordinates (0.0 to 1.0).

I have to draw the figure with random position, scale and rotation angle.

How can I do it in the best way?

Felix
  • 3,351
  • 6
  • 40
  • 68

1 Answers1

1

You could use a simple transformation with RT matrix.

Let X = (x y 1)^t be coordinates of one point of your figure. Let R be a 2x2 rotation matrix, and T be 2x1 translation vector of the transformation You plan to make. RT matrix A will have the form of A = [R T;0 0 1]. To get transformed coordinates of point X, You need to do this simple calculation AX = X', where X' are the new coordinates. Now, to get the whole figure transformed, instead of using a single column, You use a matrix where each column has x coordinate in first row, y in the second and 1 in the third row.

Of course You can try to use functions provided by OpenCV, shown in this tutorial, or ones intended for vectors of points instead of whole images, but the way above makes You actually understand what are You doing ;)

morynicz
  • 2,322
  • 2
  • 20
  • 34