我正在C++應用程序上工作。點基於另一個向量的點向量
我有
vector<Point2f> vectorAll;
vector<Point2f> vectorSpecial;
Point2f定義typedef Point_<float> Point2f;
vectorAll有1000點,同時具有vectorSpecial 10分點的2個向量。
第一步:
我需要根據他們的vectorAll爲了在vectorSpecial訂購點。 因此,像這樣:
For each Point in vectorSpecial
Get The Order Of that point in the vectorAll
Insert it in the correct order in a new vector
我可以做一個雙迴路並保存索引。然後根據它們的索引對點進行排序。然而,當我們有很多點時(例如vectorAll中的10000點和vectorSpecial中的1000點,所以這是千萬次迭代),這種方法花費的時間太長了。
什麼是更好的方法?
第二步:
在vectorSpecial幾點可能無法在vectorAll可用。我需要採取最接近它的點(通過使用通常距離公式sqrt((x1-x2)^2 + (y1-y2)^2)
)
這也可以在循環時完成,但如果有人有任何更好的方法的建議,我將不勝感激。
非常感謝您的幫助
請注意,調用STL算法不會消除循環,它只是將它們隱藏在抽象層之後。 – TemplateRex 2012-07-05 10:28:08