问题描述
我有一条折线图,以相对x
和y
点坐标(0.0到1.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?
推荐答案
您可以对RT矩阵使用简单的转换.
You could use a simple transformation with RT matrix.
让X = (x y 1)^t
为图形的一点的坐标.假设R
是2x2 旋转矩阵,而T
是2x1转换的转换向量你打算做. RT矩阵A
将具有A = [R T;0 0 1]
的形式.要获取点X的变换坐标,您需要执行此简单计算AX = X'
,其中X'
是新坐标.现在,要使整个图形变形,而不是使用单个列,而是使用一个矩阵,其中每列在第一行中具有x
坐标,在第二行中具有y
坐标,在第三行中具有1
.
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.
当然,您可以尝试使用OpenCV提供的功能,如本教程,或用于点矢量而不是整个图像的教程,但是以上方法使您真正了解了自己在做什么;)
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 ;)
这篇关于OpenCV中的坐标转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!