Given a std::vector of vertices containing some 3d integer data:
struct Vertex{
int x;
int y;
int z;
}
std::vector<Vertex> vertices = {{10, 10, 10}, {20,20,20}, {30,30,30}, {40,40,40} };
I want to calculate distances between pair of adjacent vertex:
std::vector<int> distances; // distance between adjacent vertices
I have the following for-loop:
for(int i=1; i<vertices.size(); i+=2){
int dist = calculateDistance( vertices[i], vertices[i-1]);
distances.push_back( dist );
}
Note the +=2.
Is there any STL algorithm that I can use instead of this loop? or is this even convertible to a range-based loop?
This question is different from: stackoverflow.com/q/8267806 because it wants to find distance between adjacent pairs of points.
ibefore the loop, and at the end of the loop, incrementi. That can be one of the ways.