Now that you know how to place individual markers, what happens when we combine math, loops, and coordinates? We can programmatically draw geometric patterns across the surface of the Earth!
Imagine placing a circle of markers around a central landmark, such as the famous Colosseum in Rome ($41.8902^\circ\text{ N}, 12.4922^\circ\text{ E}$).
Using circle trigonometry:
$$\text{lat} = \text{center\_lat} + R \cdot \cos(\theta)$$
$$\text{long} = \text{center\_long} + R \cdot \sin(\theta)$$
where $\theta$ sweeps from $0$ to $2\pi$ radians ($0^\circ$ to $360^\circ$), and $R$ is the radius in degrees. By running a for loop in Lua, we can place a ring of markers outlining a circular perimeter!
lat = clat + r * math.cos(theta) long = clong + r * math.sin(theta)
Move the mouse over a dotted box for more information.
Notice how simple mathematical equations transform into visual patterns on an interactive OpenStreetMap.
Now you try. Try increasing N from 12 to 24 markers, or changing the radius r to 0.03 to make a wider ring.
Type your code here:
See your results here:
To complete this lesson: Look at the loop above:
1. In the loop, lat and long have their trig multipliers set to 0.
2. Update them to use circle trigonometry:
• lat = clat + r * math.cos(theta)
• long = clong + r * math.sin(theta)
3. Click Run to draw a clock-face ring of 12 markers surrounding the Colosseum!
Share your code
Show a friend, family member, or teacher what you've done!