I'm trying to store the inforamtions of a point in a vector. So I got three coordinates for each point. To store the information I would like to use two vectors of arrays of doubles. So my code looks like this
error C2039: 'array' : is not a member of 'std'
error C2065: 'array' : undeclared identifier
error C2062: type 'double' unexpected
error C2143: syntax error : missing ';' before '>'
error C2664: 'squareDistancePoints' : cannot convert parameter 1 from 'std::array<_Ty,_Size>' to 'const std::vector<_Ty> &'
I marked the line bold.
For the squareDistancePoints function I use this code
1 2 3 4 5 6 7 8
double squareDistancePoints(const std::vector<double>& a, const std::vector<double>& b)
{
assert(a.size() == b.size());
double sum = 0;
for(size_t i = 0; i < a.size(); ++i)
sum += pow(a[i]-b[i], 2);
return sum;
}
Your function is expecting a reference to a std::vector<double> as its first parameter. However, your iterator is pointing to a std::array - because that's the type of item held in your matrix vector.
Is there any reason your function needs to take a std::vector, when your point is actually represented by a std::array?
Did you see my reply to your other post? You may not need to do any of what you are doing now. Admittedly what I proposed there could be fairly involved, but at least it might be better than the current design.
I mentioned inefficiency last time, this function seems to have O(N*(N!)) - that is factorial, efficiency which is rather bad. So with only 10 points (M) the algorithm is executed 36,288,000 times to find the shortest distances for all of them. The squareDistancePoints function goes through all of a vector as well making it quadratic factorial efficiency.
What happens after you have the shortest distances? A contouring algorithm needs to find all adjacent points in the triangular mesh, not just the nearest one. So this is why Delaunay is seen as being one of the best ways of producing a contour-able TIN (Triangular Irregular Network)
Also coder777 suggestion of using a struct for a point.
Rather than use iterators like you do, if you want to go through the whole container, consider using a range based for loop:
1 2 3 4
for (constauto Elem& : matrix) {
// your code here
// Elem is an item in matrix
}
Thanks. Yeah I saw your post and my colleague is working on this. But till we get a working function for the Delaunay Triangulation, I want to continue working on this idea. But we are working also on your approach.
Thanks man.
Ok, so you can do whatever you want - but I would seriously suggest you reconsider. Why bother with something that will be horribly inefficient? It's going to take an inordinate amount of time to do even 10050 20 points, making it almost useless.
So you have colleagues: Is this for commercial software, or open source? Either way, you really need to consider your design: get it sorted out on paper - make sure it is going to conceptually work before doing any coding. Otherwise you will all waste lots of time by inevitably having to redo things