distance between two points in 3d environment
Hello.
I'm trying to find the way to measure the distance between two point or two shapes in a 3d environment.
I have two spheres that are constantly moving and I would like to get a bang as soon as the distance between them reaches a given threshold.
Does max 6 provide a distance tool?
Thanks
The method of calculating distance in 3D space (or anyD space) is just an extension of the 2D case, i.e., the Pythogorean theorem for finding the length of the hypotenuse of a right triangle, i.e., a squared plus b squared equals c squared.
In 2D XY space, to find the distance between point 1 and point 2, you get the distance between their x coordinates and square that, add that to the square of the distance between their y coordinates, and take the square root of that sum. I.e., d = √((x2-x1)^2+(y2-y1)^2). (I hope you follow my pseudocode use of plaintext symbols: √ means "the square root of" and ^ means "to the power of".)
So for 3D it's just d = √((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)
Since you're putting the objects in their locations in 3D space yourself, you just have to keep track of their XYZ coordinates and calculate the distance between them whenever one of them moves.
here's a patch:
thanks to christopher formula I had made this with expr object:
but thanks robert because you made me discover Vexpr which is great.