How Ridges Create Topographic Maps

What Are Ridges?

Ridge generation creates topographic maps by extracting contour lines from a height field. Each line represents points at the same elevation, tracing paths across the terrain like ridgelines on a mountain range.

The Algorithm

Step 1: Generate Height Field

Create a 2D surface where each pixel represents an elevation value. This can be done using:

# Simple noise-based height field
import numpy as np
from noise import pnoise

height = pnoise(x, y, octaves=6, scale=100) + 0.5

Step 2: Calculate Distance Transform

Compute how far each point is from local peaks and valleys:

# Find peaks and valleys
peaks = (height > threshold).astype(float) * height
valleys = (height < threshold).astype(float)

# Calculate distance to nearest extremum
dist_to_peaks = compute_distance_transform(height, peaks)
dist_to_valleys = compute_distance_transform(height, valleys)

Step 3: Extract Contour Lines

Trace paths where height equals specific values:

# Extract contours at different elevations
for elevation in np.linspace(min_height, max_height, num_levels):
    contour = extract_contour(height, elevation)
    draw(contour)

Natural Examples

  • Geological formations: Sedimentary rock layers show horizontal bands of different colored minerals
  • Mountain ranges: The Alps, Himalayas, and Andes all have visible ridgelines from satellite imagery
  • Coastal erosion: Shorelines carve patterns into cliffs showing layers of rock

Digital Art Applications

Ridge generation creates:

  • Abstract landscapes: Non-photorealistic representations of terrain
  • Data visualization: Heatmaps and topographic maps of information
  • Pattern design: Decorative backgrounds with wave-like structures

Code Example

# Ridge generation in Python
import numpy as np
from scipy.ndimage import distance_transform_edt

def create_ridge_map(width, height, num_contours=10):
    # Create height field
    x = np.linspace(0, width, width)
    y = np.linspace(0, height, height)
    xx, yy = np.meshgrid(x, y)
    
    # Add noise and gradients for terrain
    height_field = pnoise(xx, yy, octaves=6, scale=20)
    height_field += 0.5 * np.sin(xx / 100) * np.cos(yy / 100)
    
    # Extract contours at evenly spaced levels
    min_h, max_h = height_field.min(), height_field.max()
    elevations = np.linspace(min_h, max_h, num_contours + 2)
    
    for level in elevations:
        contour_mask = (height_field > level).astype(float) * (height_field < level + 0.1)
        
    return height_field

Further Reading

This technique is particularly useful for creating abstract representations of mountains, valleys, and geological formations. The beauty lies in how simple mathematical rules can produce complex, natural-looking patterns.