我有两个向量:一个用5的步幅填充,所以它的大小可以是5, 10, 15, 20, 25, 30 ... 5n
。
而另一个人的步幅是6,所以它的大小是6, 12, 18, 24, 30, 36 ... 6n
我想减去这两个向量,因为它们的大小相同。因为它们都保持曲线的坐标我认为我可以减去第二个向量中的中间两个元素,所以像这样:
// The numbers are indexes
(0, 1, 2, 3, 4, 5) =
(0, 1, 3 - 2, 4, 5)
新的大小是5.但是在一般情况下使用for循环来维护和比较它们并不容易。比较应该是这样的:
// The numbers are indexes
vector<int> v1 = (0, 1, 2, 3, 4, 5);
vector<int> v2 = (0, 1, 3 - 2, 4, 5);
vector<int> v3 = v1 - v2
示例:
// Actual numbers
vector<int> v1 = (110, 210, 310, 410, 510, 610, 710, 810, 910, 1010);
vector<int> v2 = (120, 220, 320, 420, 520, 620, 720, 820, 920, 1020, 1120, 1220);
vector<int> v3 = v1 - v2; // error - vectors different size
// so we try to fix it
v2 = (120, 220, (420 - 320), 520, 620, 720, 820, (920 - 1020), 1120, 1220);
v2 = (220, 100, 520, 620, 720, 820, 100, 1120, 1220); // resized vector in the desired fasion
v3 = v1 - v2; // still not ok - the vector is of the size 9.
适用于1n
的示例,但在n > 1
时符合形状。如何做到这一点,同样的方式,当两个向量的大小发生变化时,它们总是会被填充相同的次数n
?这些向量代表线条。我想知道两个向量中每个单独点之间的距离:因此点v1[0]
与点v2[0]
之间有多远。