Compass Signpost

Show compass directions from where you are to other cities.

Run the code to find the distance from where you are to Paris. Try other cities:

SHOW/HIDE DETAILS

Type += to get a natural language input box, and type Paris in the box. Evaluate with + to get an exact, computable representation of Paris:

In[1]:=
X
Out[1]=

Find the distance from here to Paris:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Find the direction from where you are to Paris. Try other cities:

SHOW/HIDE DETAILS

Get the direction to Paris:

In[1]:=
X
Out[1]=

The result is the angle clockwise from north.

HIDE DETAILS
In[1]:=
X
Out[1]=

Get the x-y coordinates of Paris relative to where you are:

Hint: type deg to get the degree symbol (°).

SHOW/HIDE DETAILS

GeoDistance and GeoDirection give the distance and direction you would need to travel from your present location to reach a given city.

To plot that path on a flat surface, you need to convert {distance,direction} coordinates to {x,y} coordinates. {distance,direction} coordinates are similar to {r,θ} polar coordinates, but the direction value goes the opposite angular direction and the zero is where 90° is in polar coordinates. Subtracting the direction from 90° gives the polar coordinate angle. Use CoordinateTransform to convert that into Cartesian {x,y} coordinates in miles:

In[1]:=
X
Out[1]=

Remove the units from the values with QuantityMagnitude:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Draw lines from where you are to the locations of various other cities. Try other cities:

SHOW/HIDE DETAILS

This expression gives the {x,y} coordinates of Paris relative to your current position:

In[1]:=
X
Out[1]=

To get the {x,y} coordinates of more than one city, its easiest to turn that expression into a pure function. This expression has been cast in pure function form by replacing the occurrences of Paris with hash signs (#) and following it with an ampersand (&). Applying the function to Paris gives the same result as above:

In[2]:=
X
Out[2]=

Use Map (/@) to get the {x,y} coordinates of each city in a list:

In[3]:=
X
Out[3]=

Draw a line from where you are now ({0,0}) to the coordinates of each city:

In[4]:=
X
Out[4]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Label the cities with their names:

SHOW/HIDE DETAILS

Add the names of the cities to the graphic. To avoid having to repeat the lengthy {x,y} coordinate calculation, first factor it out of the expression with With:

In[1]:=
X
Out[1]=

Now you can easily add the Text primitive at the endpoint pt of the line:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Add the distances. Try other cities:

SHOW/HIDE DETAILS

Column formats a list of items as a column:

In[1]:=
X
Out[1]=

Use Column to add the distance underneath the city name:

In[2]:=
X
Out[2]=

Make the city name bold so that it stands out:

In[3]:=
X
Out[3]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Share ItMake a website that shows distances from your location to various cities:

SHOW/HIDE DETAILS

Deploy a form that asks for a list of cities and makes a diagram of distances to them:

In[1]:=
X
Out[1]=

Click the link in the output to visit the site. Separate the cities you enter with semicolons (;) rather than spaces or commas, since both of those can occur in city names.

Share the link by right-clicking it and choosing Copy Address. Paste the link into an email, tweet, or other message.

HIDE DETAILS
In[1]:=
X
Out[1]=