Advertisement

How to calculate the distance between two 7in 3D

Started by April 24, 2002 01:06 PM
4 comments, last by yanuart 22 years, 9 months ago
How to calculate the distance between two in 3D (x1,y1,z1) & (x2,y2,z2) ?? Sorry about my math, I know how to do it in 2D, is it the same ?? Can I use vector operation (dot, cross, multiply) to do it ?? what exactly does dot, cross, mul mean (I mean how to implement in solving problem)?? Thanks
Ride the thrill of your life
Play Motorama
If I''m not mistaken, you can use this:

Distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)
I am always open to feedback, positive or negative...
Advertisement
correct.

subtracting one point from the other gives you a vector that is the length of the distance between the points.

then you use basically 3D pythagorean theorem as per the equation above.

-me
Hmm.. assuming that I have 2 bounding circles .. errr.. balls with radius r1 and r2..
how can I check if those two collided or not ?
The idea is =
if (sqr(x1-x2)+sqr(y1-y2)+sqr(z1-z2) < sqr(r1)+sqr(r2)) then
collided
else
not collided
??? is it true ?? Can somebody explain the theory behind those equation ??

Ride the thrill of your life
Play Motorama
umm...

do not use a square root - keep the values squared
Your comparison is incorrect. The correct comparison is

length(c2 - c1) < r1 + r2

which expands to (if you eliminate the square roots)

(x2 - x1)² + (y2 - y1)² + (z2 - z1)² < (r1 + r2)²

Cédric

This topic is closed to new replies.

Advertisement