lightningdistance

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 1 Imported by: 0

README

lightning-distance

Go Reference

Compute the distance to a lightning strike from the delay between seeing the flash and hearing the thunder. Pure, dependency-free Go physics, with no external data source and no network access.

The light from a strike arrives essentially instantly, so the whole measurable delay is sound travel time. The speed of sound in air is modelled with the standard temperature-corrected approximation v = 331.3 + 0.606 × T (m/s, T in °C) — about 343 m/s at 20 °C.

Install

go get github.com/theluckystrike/lightning-distance

Quick example

package main

import (
	"fmt"

	lightningdistance "github.com/theluckystrike/lightning-distance"
)

func main() {
	// 5-second flash-to-thunder delay at 20 C
	fmt.Println(lightningdistance.DistanceKm(5.0, 20.0))    // ~1.717 km
	fmt.Println(lightningdistance.DistanceMiles(5.0, 20.0)) // ~1.067 mi
	fmt.Println(lightningdistance.DangerVerdict(5.0))        // "very-close"

	// Rule of thumb
	fmt.Println(lightningdistance.MilesFromSeconds(10.0)) // 2.0 mi
}

API

Function Description
SpeedOfSound(tempC float64) float64 Speed of sound in m/s (v = 331.3 + 0.606·T).
DistanceMeters(delaySeconds, tempC float64) float64 Strike distance in meters (negatives clamped to 0).
DistanceKm(delaySeconds, tempC float64) float64 Strike distance in kilometers.
DistanceMiles(delaySeconds, tempC float64) float64 Strike distance in miles (international mile = 1609.344 m).
MilesFromSeconds(delaySeconds float64) float64 The ~5-seconds-per-mile rule of thumb.
KmFromSeconds(delaySeconds float64) float64 The ~3-seconds-per-kilometre rule of thumb.
MetersToMiles(meters float64) float64 / MetersToKm Unit helpers.
EstimateTemperatureFromSpeed(speedMps float64) float64 Inverse of SpeedOfSound.
DangerVerdict(delaySeconds float64) string imminent / very-close / seek-shelter (30/30 rule) / near / far.

License

MIT.

Documentation

Overview

Package lightningdistance computes the distance to a lightning strike from the delay between seeing the flash and hearing the thunder. The light from the strike arrives essentially instantly (light travels ~300,000 km/s, so even a 50 km strike is seen in well under a millisecond), so the entire measurable delay is sound travel time.

Written and maintained by the author of https://earlythunder.com/.

Speed of sound in air depends on temperature. At 20 °C (68 °F) dry air it is ~343 m/s. DistanceKm uses a temperature-corrected speed of sound:

v = 331.3 + 0.606 * T   (m/s, T in Celsius)

which is the standard linear approximation for the speed of sound in air.

Quick example:

km := lightningdistance.DistanceKm(5.0, 20.0) // 5 s delay, 20 C
// km ~= 1.715  (~331.3 + 0.606*20) * 5 / 1000

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClosestApproach

func ClosestApproach(delaySeconds, tempC float64) float64

ClosestApproach returns the minimum distance (meters) from a strike given the observed delay, clamped to >= 0 (you cannot be inside the strike point).

func DangerVerdict

func DangerVerdict(delaySeconds float64) string

DangerVerdict returns a plain-language safety read on how far away a strike is. The "30/30 rule" says seek shelter if thunder is within 30 seconds (~10 km) and wait 30 minutes after the last thunder.

func DistanceKm

func DistanceKm(delaySeconds, tempC float64) float64

DistanceKm returns the strike distance in kilometers.

func DistanceMeters

func DistanceMeters(delaySeconds, tempC float64) float64

DistanceMeters returns the distance to a lightning strike in meters from the flash-to-thunder delay (seconds) at a given air temperature (Celsius). It returns 0.0 if the delay is negative.

func DistanceMiles

func DistanceMiles(delaySeconds, tempC float64) float64

DistanceMiles returns the strike distance in miles (1 mile = 1609.344 m).

func EstimateTemperatureFromSpeed

func EstimateTemperatureFromSpeed(speedMps float64) float64

EstimateTemperatureFromSpeed returns the air temperature (Celsius) implied by an observed speed of sound (m/s), the inverse of SpeedOfSound. Useful when calibrating against a measured sound speed.

func KmFromSeconds

func KmFromSeconds(delaySeconds float64) float64

KmFromSeconds is the popular 3-seconds-per-kilometre rule (assuming ~20 °C), returning distance in km. Roughly: count seconds, divide by 3.

func MetersToKm

func MetersToKm(meters float64) float64

MetersToKm converts meters to kilometers.

func MetersToMiles

func MetersToMiles(meters float64) float64

MetersToMiles converts meters to miles using the international mile.

func MilesFromSeconds

func MilesFromSeconds(delaySeconds float64) float64

MilesFromSeconds is the popular 5-seconds-per-mile rule (assuming ~20 °C), returning distance in miles. Roughly: count seconds, divide by 5.

func SpeedOfSound

func SpeedOfSound(tempC float64) float64

SpeedOfSound returns the speed of sound in air in m/s for a given air temperature in degrees Celsius, using the standard linear model v = 331.3 + 0.606 * T.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL