The "Distance between" Operator Block
-
Prerequisite
What is “Direct” and “Manhattan” distance?
Suppose you are at the start point on the map above, and you want to travel to the stop point. If you can walk in a straight line, then the length of this line is the direct distance between these 2 points. This is shown as the yellow line on the map.
However, in many situations, you can not travel in a straight line. For example, there may be houses or buildings between the street blocks, as in the case of Manhattan city. In this case, you have to walk along the vertical or horizontal streets. The total length of these lines is the “Manhattan distance” between the 2 points.
Below are some more examples of Direct and Manhattan distances between the START and STOP points;
Example 1:
Example 2:
Example 3:
The Block
The “Distance between x() y() and x() y()/ direct” is a reporter block in the operators category.
How does this block work?
This block tells the distance between two specified points.
In CreatiCode, a “point” or “position of a sprite” is defined by an “x position” and a “y position”.
You need to input the position values of two different points in the block, and choose “Direct” or “Manhattan” by clicking on the drop-down menu.Here is how it works;