19 April 2010

Finding the distance in 3D space between two points: Theory and Real World Use

First, the theory....

Individual points in three dimensional space can be represented on a Cartesian coordinate grid. Each point is noted as three numbers separated by commas, of the form "X, Y, Z," where each number is for a different dimension. The simplest way to calculate the distance between two points is to apply the Pythagorean theorem twice.

Step 1: Suppose your two points are X1, Y1, Z1 and X2, Y2, Z2. If Y1 = Y2 and Z1 = Z2, leaving only the two X numbers different from each other, what you have is a one-dimensional problem. Subtract the smaller X from the larger X.

For example, if your points are 3, 4, 7 and 11, 4, 7, you would subtract as 11 minus 3, giving you a distance of 8.

Step 2: Suppose Z1 = Z2, but the X numbers and Y numbers are both different from each other. What you have is a two-dimensional problem. To solve it, imagine a right-angled triangle where the distance between the two points is the length of the hypotenuse. The Pythagorean theorem states that A^2 + B^2 = C^2. The length of A would be X2-X1, and the length of B would be Y2-Y1. The distance, C, would be the square root of (X2-X1)^2 + (Y2-Y1)^2.

For example, if your points are 3, 4, 7 and 11, 10, 7, you would take the square root of (11-3)^2 + (10-4)^2, or 64 + 36, or 100. This gives you a distance of 10.

Step 3: Suppose all three pairs of numbers are different. Now it's a three-dimensional problem. Calculate C from the X and Y numbers, as in Step 2. This gives you one of the two non-hypotenuse sides of a new right triangle. The other non-hypotenuse side is Z2 - Z1. Applying the Pythagorean theorem again, you would take the square root of (Z2 - Z1)^2 + the first C^2.

For example, if your points are 3, 4, 7 and 11, 10, 22, you would take the square root of (22 - 7)^2 + 10^2, or 225 + 100, or 325. Your distance would be approximately 18.




So much for the mathematical theory. Now, how it would be done if you had an actual physical object, and you couldn't just insert a ruler up inside to get it directly....

To calculate the distance between the upper left front corner and lower right rear corner of a box-shaped object, without measuring from the inside of the object, you only need to know its outside dimensions.

Step 1: Measure the length, width and height of the object.

Step 2: Calculate the squares of each. Multiply length times length, width times width, and height times height. For example, if length is 6, width is 8, and height is 15, their squares would be 36, 64, and 225.

Step 3: Add all of these together. Then take the square root. In our example, that would be the square root of 36 + 64 + 225, which adds up to 325. 18 times 18 is 324, so the square root of 325--and the final answer--is a little over 18.

No comments: