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, y and z are floats/doubles.
I want to find the distance between these two points. One way to do it is :
square_root(x_diffx_diff + y_diffy_diff + z_diff*z_diff)
But this is probably not the most efficient way . (e.g. a better formula or a ready made utility in math.h etc )
Question 2:
Is there a better way if I just want to determine if P and Q are in fact the same points?
My inputs are x, y and z coordinates of both the points.
Thank you
Do you need the actual distance? You could use the distance squared to determine if they are the same, and for many other purposes. (saves on the sqrt operation)