randRangeExclude( -8, 10, [0, 1, 2] ) randRangeExclude( -10, 8, [-1, -2, -3, -4] ) randRangeExclude( -8, 8, [-1, 0] ) randRangeExclude( -8, 8, [-1, 0] ) abs( X2 - X1 ) abs( Y2 - Y1 ) X_DIST * X_DIST + Y_DIST * Y_DIST

Find the distance between the points (X1, Y1) and (X2, Y2).

graphInit({ range: 11, scale: 20, tickStep: 1, labelStep: 1, unityLabels: false, labelFormat: function( s ) { return "\\small{" + s + "}"; }, axisArrows: "<->" }); label([ X1, Y1 ], "(" + X1 + ", " + Y1 + ")", "left", { color: "#0969a2" } ); label([ X2, Y2 ], "(" + X2 + ", " + Y2 + ")", "right", { color: "#a62add" } ); circle([ X1, Y1 ], 3 / 20, { stroke: "none", fill: "#0969a2" } ); circle([ X2, Y2 ], 3 / 20, { stroke: "none", fill: "#a62add" } );
HYP2

Change in x: X2 - negParens(X1) X1 - negParens(X2) = X_DIST

style({ color: "#679b00", stroke: "#679b00" }, function() { line( [ X1, Y1 ], [ X2, Y1 ] ); label( [ ( X1 + X2 ) / 2, Y1 ], X_DIST, "above" ); });

Change in y: Y2 - negParens(Y1) Y1 - negParens(Y2) = Y_DIST

style({ color: "#a66000", stroke: "#a66000" }, function() { line( [ X2, Y1 ], [ X2, Y2 ] ); label( [ X2, ( Y1 + Y2 ) / 2 ], Y_DIST, "left" ); });

The distance is the length of the hypotenuse of this right triangle.

style({ stroke: "#ff4900" }, function() { line( [ X1, Y1 ], [ X2, Y2 ] ); });

By the Pythagorean Theorem, that length is equal to:

\sqrt{X_DIST^2 + Y_DIST^2}

{}= \sqrt{Math.pow( X_DIST, 2 ) + pow( Y_DIST, 2 )}

{}= formattedSquareRootOf(HYP2)

The distance is equal to the length of the side, which is X_DIST+Y_DIST