Efficient way of finding distance between two 3D points

后端 未结 11 1061
借酒劲吻你
借酒劲吻你 2021-02-01 06:42

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,

11条回答
  •  被撕碎了的回忆
    2021-02-01 07:14

    Note that when using sqrt(dx*dx+dy*dy+dz*dz) the sum of squares might overflow. hypot(dx, dy) computes a distance directly without any chance of overflow. I'm not sure of the speediest 3d equivalent, but hypot(dx, hypot(dy, dz)) does the job and won't overflow either.

提交回复
热议问题