View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Finding length of 3D line when given end points.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Anonymous Poster_Anonymous Poster_*  Guests

Posted 25 August 1999 - 09:20 PM

Anyone know how to calculate the length of a line in 3D when you know the endpoints.

Like (x1, y1, z1) and (x2, y2, z2).

Thanks!

### #2mutex  Members

Posted 25 August 1999 - 07:00 PM

here's C++:

float x = x1 - x2;
float y = y1 - y2;
float z = z1 - z2;

distance = sqrt(x*x + y*y + z*z)

### #3Anonymous Poster_Anonymous Poster_*  Guests

Posted 25 August 1999 - 07:22 PM

Thanks for your quick response Mutex.

### #4Pryankster  Members

Posted 25 August 1999 - 09:20 PM

Remember, however, that for many applications of the distance function (checking for collisions against bounding spheres, etc). You can usually get away with using the "distance squared", and avoid doing the (SLOW!) square-root operation.

i.e.: if you have two billiard balls which are 2 units in diameter, to see if they collide, you can check to see if their centers are within 4 units of each other, avoiding a square root operation.

-- Pryankster

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.