[英]Horizontal and vertical flip on linesegment
I have a set (c++ vector) of points (x,y) that defines a line. 我有一组(c ++矢量)点(x,y)定义了一条线。 How do I implement a function that returns the samle line, flipped horizontal and vertical relative to its own size?
我如何实现一个函数,该函数返回相对于其自身大小水平和垂直翻转的样本线?
I assume that you mean you're not flipping with respect to some fixed origin; 我以为您的意思是您并不是针对某个固定的原产地; you're flipping with respect to the centroid of the line.
您正在相对于直线的质心翻转。
Here's some pseudocode: 这是一些伪代码:
Get the min and max y and x in the vector
Height = yMax - yMin
Width = xMax - xMin
yCentroid = yMin + (Height / 2)
xCentroid = xMin + (Width / 2)
for each point...
xNew = xMax - (xOld - xMin)
yNew = yMax - (yOld - yMin)
For example, if we had a simple 3-point line from (-5, 3) to (7, 4) to (11, -1), this would give us a flipped line from (11, 0) to (-1, -1) to (-5, 4). 例如,如果我们有一条简单的三点线,从(-5,3)到(7,4)到(11,-1),这将给我们一条从(11,0)到(-1)的翻转线,-1)至(-5,4)。 This is shown in the blue example below.
这在下面的蓝色示例中显示。
It also works for several points, as shown in the green example below. 它也适用于多个点,如下面的绿色示例所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.