Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    The "Distance between" Operator Block

    2D Blocks
    1
    1
    186
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

       

      Prerequisite

      • Working with Blocks

       

      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;


       

      1 Reply Last reply Reply Quote 0
      • First post
        Last post