我想做什么:
1。统一缩放点周围的点阵列。 2.一个点必须是一系列点的平均点。
下面的代码似乎有用,但我不知道这是否是正确的方法。
我知道均匀缩放只是将点乘以某个值,但这是在0,0,0点上缩放,如何围绕平均点进行缩放?
可以通过以下步骤细分代码:
最后一点第5点完全来自检查值的总长度。
我之前提出的所有例子都是在数学中使用矩阵,我真的无法读取矩阵运算。
这是正确的统一缩放方法吗,如果不能指出我做错了什么?
//Get center of a curve
//That is average of all points
MatMxN curveCenter = MatMxN::Zero(2, 1); //This is just 1 vector/point with x and y coordinates
for (int i = 0; i < n; i++)
curveCenter += points.col(i);
curveCenter /= n;
//Scaling value
float ratio = 1.3;
//Get vector pointing to center and move by ratio
for (int i = 0; i < n; i++) {
MatMxN vector = curveCenter - points.col(i);
MatMxN unit = vector.normalized();
points.col(i) += unit*(1 - ratio)*0.5; //points.col(i) this is point in array
}
答案 0 :(得分:2)
要使用特定中心点( 0 除外)缩放点,请按以下步骤操作:
MatMxN vector = points.col(i) - curveCenter;
vector *= ratio
points.col(i) = vector + curveCenter
可以将此方法解析为与您的公式类似的远程方法。让我们调用中心C
,缩放点P0
,缩放点P1
和缩放系数s
。以上3个步骤可写为:
v0 = P0 - C
v1 = s * v0
P1 = v1 + C
=&GT;
P1 = s * P0 + C * (1 - s)
现在我们为某些P1 = P0 + x
定义x
:
P0 + x = s * P0 + C * (1 - s)
=&GT;
x = s * P0 + C * (1 - s) - P0
= C * (1 - s) - P0 * (1 - s)
= (C - P0) * (1 - s)
因此,更新可以写成如下,而不是使用上述3个步骤:
MatMxN vector = curveCenter - points.col(i);
points.col(i) += vector * (1 - ratio);
但是,我更倾向于反向编写减法,因为它更接近原始步骤,更容易通过直觉理解:
MatMxN vector = points.col(i) - curveCenter;
points.col(i) += vector * (ratio - 1);
我不知道您在哪里找到了规范化和*0.5
想法。