In my program I put specific coordinates into a list. However, the algorithm sometimes puts the same coordinates into the list twice. In order to avoid that, I do the standard approach by comparing the EPSILON value to the absolute difference of both x and y values off all positions in the list:
bool doubleEqual(double x1, double y1, double x2, double y2){
if( (fabs(x1-x2) < EPSILON) && (fabs(y1-y2) < EPSILON) ){
return TRUE; // particle is already in list
}
return FALSE; // particle is not in the list
}
I have several questions:
1) Is this implementation to compare the position of two particles even correct?
2) How small can I choose EPSILON? (The particles can come really close to each other)
3) Is there any faster / or more robust implementation to compare the position of particles?