I am writing a code in C++ and want to compute distance between two points. Question 1:
I have two points P(x1, y1, z1) and Q(x2, y2, z2) , where x,
No there is no better way.
The implementation of square_root
might be optimised.
If you are comparing two distances and want to know the longer, but do not care about what the actual distance is, then you can simply ingore the square-rooting step completely and manipulate your distances still squared. This would be applicable to comparing two pairs of points to determine if they are the same distance apart, for example.