Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Finding length of 3D line when given end points.

This topic is 6902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

here's C++:

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

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Thanks for your quick response Mutex.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!