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,
You may try to use SSE extensions. For example, you can init two vectors A(x1,y1,z1) and B(x2,y2,z2):
_m128 A = _mm_set_ps(x1, y1, z1, 0.0f)
_m128 B = _mm_set_ps(x2, y2, z2, 0.0f)
Then compute diff using _mm_sub_ps:
__m128 Diff = _mm_sub_ps(A, B)
Next compute sqr of diff:
__m128 Sqr = __mm_mul_ps(Diff, Diff)
And finally:
__m128 Sum = add_horizontal(Sqr)
__m128 Res = _mm_sqrt_ss(Sum)
Res[0] will be filled with your answer.
P.S. add_horizontal is a place for optimization