I am trying to loop through a three-dimensional vector. I have one vector containing multiple vectors of x and y coordinates. Lets call the parent vector v0, the vector containing the coordinates v1, and the pair of coordinates v2.
For any v2 in any v1, if the x value of v2 is equal to the x value of another v2 in any v1, I want to add the y values of the v2. if a v2 doesn't have any matching y values, add it to the y value at the point in the next v1 (I already have a function that does this)
In the end I only have one v1 which I will render. The size of a v1 is unknown, but will always have some v2 with the same x value as a v2 in another v1
The context is essentially I have a set of graphs that I want to "add" to make fractal noise. I am successfully generating the set of graphs, but am unsure how to add them.
Here is my code so far
(also for those unfamiliar with sfml, sf::vector2f is just a vector of two floats. These are the coordinates. you can access the value of a coordinate with vec.y/vec.x)
void Noise() {
std::vector<sf::Vector2f> finalGraph;
std::vector<sf::Vector2f> singleNoise;
std::vector < std::vector<sf::Vector2f>> allGraphVec;
float persistance = 0.5;
int nOOPM1 = 4;
//generates the graphs to be added
for (int i = 0; i < nOOPM1; i++) {
float frequency = pow(2, i);
float amplitude = pow(persistance, i);
singleNoise =
this->generateNoise(frequency, 300 * amplitude);
allGraphVec.emplace_back(singleNoise);
}
//Do what I described above over here
//This is pseudoCode I have no idea what Im doing here
for(auto &v : allGraphVec){
if(v1 has a v2 == to another v1's v2){
add the v2
take the added value and put it in finalgraph
}
}
//this function just draws a line between each point in the graph, making it a graph not a series of points
for (std::vector<sf::Vector2f>& v : allGraphVec) {
v = this->interpolateNoise(v, 3, 1000);
}
//this will be rendered
this->graphToBeRendered = finalGraph
};
Sorry if this is a bit confusing.