Pythagorean theorem

Consider a right-angle triangle with side lengths as indicated:

The lengths aa and bb are called the side lengths, and cc is called the (length of the) hypotenuse. The Pythagorean theorem says that these are related by the equation

a2+b2=c2.a^2 + b^2 = c^2.

This can be visualized in terms of the areas formed by squares drawn on the sides of the triangle:

Proof

Let's see why the Pythagoream theorem is true. We'll draw two squares, both having side length a+b,a+b, and divide them in different ways:

The left square says that

(a+b)2=a2+2ab+b2(\red a + \blue b)^2 = \red{a^2} + \violet{2ab} + \blue{b^2}

The right square says that

(a+b)2=c2+2ab(\red a + \blue b)^2 = \green{c^2} + \violet{2ab}

Setting these equal to each other, we get

a2+2ab+b2=c2+2aba2+2ab+b2=c2+2aba2+b2=c2.\begin{aligned} \red{a^2} + \violet{2ab} + \blue{b^2} &= \green{c^2} + \violet{2ab}\\ \red{a^2} + \xcancel{\violet{2ab}} + \blue{b^2} &= \green{c^2} + \xcancel{\violet{2ab}}\\ \red{a^2} + \blue{b^2} &= \green{c^2}. \end{aligned}

Three dimensions

If v=(x,y)v=\ivec{x,y} is a vector in R2,\VecR2, the Pythagorean theorem implies that the length of vv is

x2+y2.\sqrt{x^2+y^2}.

Similarly, if A=x1,y1A=\ipt{x_1,y_1} and B=x2,y2B=\ipt{x_2,y_2} are points in A2,\AffR 2, the Pythagorean theorem tells us that the distance between these is

(x1x2)2+(y1y2)2\sqrt{(x_1-x_2)^2 + (y_1-y_2)^2}

How can we extend this to higher dimensions? That is, if A=x1,y1,z2A=\ipt{x_1,y_1,z_2} and B=x2,y2,z2B=\ipt{x_2,y_2,z_2} are points in A3,\AffR3, what is d(A,B)?\Dist AB? Writing AB=v=(x,y,z),A-B=v=\ivec{x,y,z}, this is the same as asking for the length of v.v.

A naive guess is that the length of v=(x,y,z)v=\ivec{x,y,z} might be

x3+y3+z33.\sqrt[3]{x^3+y^3+z^3}.

But this can't be true, since the length of (x,y,0)\ivec{x,y,0} should be the same as the length of (x,y).\ivec{x,y}. That is, the appearance of the number 22 in the Pythagorean theorem isn't related to the problem being in two dimensions.

Instead, we can introduce the point

C=x2,y2,z1,C=\ipt{x_2,y_2,z_1},

which has 11 component in common with AA and 22 components in common with B.B. The points A,A, B,B, and CC lie in a common plane, and we can apply the "2d" Pythagorean theorem within this plane to get d(A,B)\Dist AB in terms of d(A,C)\Dist AC and d(B,C).\dist BC. The vertical distance d(B,C)\dist BC is just z2z1,|z_2-z_1|, and we can compute d(A,C)\Dist AC by the "2d" Pythagorean theorem. This is illustrated in the animation below.

Access source on GitHubSource

Distance

APIs

In Javascript, we can compute the lengths of vectors using Math.hypot().

Console

In THREE.js, we have the following APIs for calculating distances and lengths:

For the "squared" methods, note that when x,y0x,y\ge 0 we have xyx\ge y if and only iff x2y2.x^2 \ge y^2.

Exercises

  1. Make an app to draw circles like below. (Don't look at the source until you've tried it yourself.)

    Access source on GitHubSource
  2. Extend the above app to disallow drawing circles which overlap.