Suppose your player is at (0, 2) and a character is at (4, 5)…​

1 Identify the values of x1, y1, x2, and y2

x1 y1 x2 y2

(x-value of 1st point)

(y-value of 1st point)

(x-value of 2nd point)

(y-value of 2nd point)

What is the distance between your player and the character?

  • We can use line-length to computer the horizontal and vertical distances and then use those to find the diagonal distance.

    • The horizontal distance between x1 and x2 is computed by line-length​(​x2, x1​).

    • The vertical distance between y2 and y1 is computed by line-length​(​y2, y1​).

  • The hypotenuse of a right triangle with legs the lengths of those distances is computed by: line-length(x2, x1)2 + line-length(y2, y1)2

  • So, when we substitute these points in, the distance between them will be computed by:

line-length(4, 0)2 + line-length(5, 2)2

2 The points are (0,2) and (4,5). Why aren’t we using line-length​(​0, 2​) and line-length​(​4, 5​)?

3 Translate the expression above, for (0,2) and (4,5) into a Circle of Evaluation below.

Hint: In our programming language num-sqr is used for x2 and num-sqrt is used for x

circles of distance

4 Convert the Circle of Evaluation to Code below.

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.