hole

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hole supplies black-hole maths for a renderer: Kerr geometry in Kerr–Schild form, null and timelike geodesics from Hamilton’s equations, conserved quantities, redshift, and the frame of a falling camera.

Only the standard library is imported. The package describes geometry and motion, not materials or finished pictures. gpu.go supplies float32 shader parameters and CPU reference stepping; it does not execute GPU work.

G and c are one. Mass sets the length scale, coordinates are (t, x, y, z), the spin axis is z, the metric signature is (-, +, +, +), and momentum is covariant. Formula-derived constants and their sources are in numbers.go. Chosen integration tolerances are in choices.json, with their authors.

The intended boundary leaves relativity here and moves rendering policy to Slayer. March, PaceIn, Hovering, ClosestApproach, DeflectionAngle, Fate, the choices used by Advance and ClassifyRay, choices.json, and gpu.go are part of that proposed migration. They remain implemented in this checkout.

Step already advances a geodesic at a caller-supplied interval. Test expectations and their provenance live in testdata/hole.json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(covector, vector Vec4) float64

Dot contracts a covector with a contravariant vector. It applies no additional metric sign; lowering supplies that beforehand.

func ErrNothingStill

func ErrNothingStill() error

ErrNothingStill identifies a location where SetCamera cannot hold an observer stationary: inside the ergosurface or horizon. The function returns a stable error value for errors.Is comparisons.

func Shift

func Shift(momentumAtEye, observer, momentumAtEmitter, emitter Vec4) float64

Shift returns photon energy at the eye divided by energy at the emitter, contracting each endpoint momentum with that observer’s four-velocity. Above one is bluer; below one is redder. Relative motion and gravitational redshift both contribute.

Only the time component of momentum is generally conserved. Reusing one endpoint’s momentum at the other is valid only when that observer’s velocity has no spatial components.

Types

type Fate

type Fate int

Fate records why a march stopped. It belongs to the proposed move of rendering policy to Slayer; see the package documentation.

const (
	Escaped  Fate = iota // past the far radius, and straight from there
	Captured             // not coming back: see March
	// The step budget ran out, or the ray stopped being a number
	Stuck
)

The fates.

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame is an observer’s orthonormal tetrad: four-velocity first, then spatial axes. Metric Gram–Schmidt starts from the coordinate x, y, and z axes.

func (Frame) Observer

func (frame Frame) Observer() Vec4

Observer is the frame's first vector, the observer's four-velocity.

func (Frame) XAxis

func (frame Frame) XAxis() Vec4

XAxis is the frame's second vector, the spatial axis made from x.

func (Frame) YAxis

func (frame Frame) YAxis() Vec4

YAxis is the frame's third vector, the spatial axis made from y.

func (Frame) ZAxis

func (frame Frame) ZAxis() Vec4

ZAxis is the frame's fourth vector, the spatial axis made from z.

type GPUBlackHole

type GPUBlackHole struct {
	// contains filtered or unexported fields
}

GPUBlackHole is a hole and stationary-camera adapter for shaders. ShaderParams exports float32 constants; StepRay supplies CPU reference steps and diagnostics for comparison with a shader.

No GPU work runs here. Batches step sequentially on one core. SetCamera mutates the adapter, so callers must synchronize concurrent use with camera changes. This adapter belongs to the proposed rendering-policy migration to Slayer.

func NewGPUBlackHole

func NewGPUBlackHole(mass, spin float64) (*GPUBlackHole, error)

NewGPUBlackHole validates mass and spin through NewHole and creates an adapter without a camera. Invalid geometry returns NewHole’s error.

func (*GPUBlackHole) Hole

func (gb *GPUBlackHole) Hole() Hole

Hole returns the underlying black-hole geometry.

func (*GPUBlackHole) SetCamera

func (gb *GPUBlackHole) SetCamera(position Vec3) error

SetCamera installs a stationary observer and caches its frame for subsequent steps and shader parameters. Where that observer cannot exist, it returns ErrNothingStill and preserves the previous camera.

func (*GPUBlackHole) ShaderParams

func (gb *GPUBlackHole) ShaderParams() ShaderParams

ShaderParams returns float32 constants for the hole and current camera. Before SetCamera, the camera fields are zero.

func (*GPUBlackHole) StepRay

func (gb *GPUBlackHole) StepRay(ray *Ray, stepSize float64) RayStep

StepRay advances a ray in place by one Runge–Kutta interval and reports the new state and invariants. Diagnostics cost more than twice the step alone; use Hole.Step or March when those reports are unnecessary.

func (*GPUBlackHole) StepRaysBatch

func (gb *GPUBlackHole) StepRaysBatch(
	reports []RayStep, rays []Ray, stepSize float64,
) []RayStep

StepRaysBatch advances rays in order and returns one report per ray. It reuses reports when capacity permits; pass nil initially, then reuse the returned slice to avoid repeated allocation.

type Hole

type Hole struct {
	// contains filtered or unexported fields
}

Hole stores mass M and spin A = J/M in geometric length units. The spin axis is z, with rotation from x toward y. Use NewHole to validate the range before calling the geometric methods.

func NewHole

func NewHole(mass, spin float64) (*Hole, error)

NewHole constructs a Kerr hole with mass M and spin A = J/M, both in length units with G = c = 1. It requires a finite positive mass within the arithmetic bounds, and 0 <= A < M.

Mass limits are about 1.2e-77 to 5.8e76 in the caller’s length unit. The fourth powers used by radius and kernel must resolve the hole’s own horizon without overflow or loss of normal precision; see lightest and heaviest.

Negative spin is represented by reversing the z axis instead. A = M is excluded because the two horizons coincide; above it there is no black-hole horizon. Zero spin is allowed as the Schwarzschild limit used by the closed-form tests. Invalid inputs return nil and an error.

Coordinates farther than about 1.2e77 overflow the radius calculation regardless of mass. Constructor checks cannot prevent that; choose a suitable coordinate scale.

func (Hole) Advance

func (hole Hole) Advance(ray Ray, properTime float64) (Ray, bool)

Advance integrates a body through proper time and reports whether it is inside the horizon. Steps use the configured fraction of pace at the smaller of radius and distance to the ring.

The inside flag uses the horizon itself, not the ray capture margin. Integration stops before leaving the supported chart: near the ring or its spanning disc within the configured singularity margin, and at a spinning hole’s inner horizon. Remaining proper time is unspent.

Beyond the inner horizon, off-equator trajectories can turn outward through a region this chart does not cover. Near the singularity, pace tends to zero and stepping into the zero-radius flat fallback would be meaningless.

Advance uses choices.json and is included in the proposed migration of marching policy to Slayer; see the package documentation.

func (Hole) Arriving

func (hole Hole) Arriving(position Vec3, frame Frame, direction Vec3) Ray

Arriving constructs light seen coming from a local frame direction for backward camera tracing. Its negated photon momentum advances the integration parameter while coordinate time runs backward. Observer energy contractions Dot(P,u) are then positive.

At zero spin it follows the spatial path of Null sent toward the same direction. Frame dragging separates those paths with spin.

func (Hole) Carter

func (hole Hole) Carter(ray Ray) float64

Carter returns the conserved Carter constant, alongside energy and Lz. Kerr–Schild and Boyer–Lindquist coordinates share z = R cos(theta):

Q = p_theta² + cos²(theta) *
    (A²(mu² - E²) + Lz² / sin²(theta)).

Here mu² = -2H: zero for light and one for a unit-mass body. At zero spin Q is total angular momentum squared minus Lz². It is NaN on the disc inside the ring, where R is zero.

func (Hole) Circular

func (hole Hole) Circular(position Vec3) Vec4

Circular returns prograde circular four-velocity at the position, using the Kerr correction to Kepler’s angular rate as measured at infinity. That rate agrees in these and Boyer–Lindquist coordinates.

Inside the prograde photon orbit this motion is not timelike and returns NaN components. Where admissible, it can exist inside the ergosphere even though Static cannot.

func (Hole) ClassifyRay

func (hole Hole) ClassifyRay(ray Ray) RayClassification

ClassifyRay marches a trajectory to classify it as escaping, plunging, or circulating. Escape uses the larger of the configured multiple of starting radius and the fixed far-radius floor. Exhausting the classification step budget assigns circulating.

This is a finite integration classification: a bound orbit extending beyond the threshold can read as escaping, and a nonfinite ray as circulating. It uses marching choices and belongs to the proposed move of rendering policy to Slayer.

func (Hole) ClosestApproach

func (hole Hole) ClosestApproach(ray Ray, steps int) float64

ClosestApproach returns the smallest radius sampled while stepping until an outward turn, capture, or exhausted budget, including the last state. An initially outgoing ray returns its starting radius.

For captured light this only bounds the radius where integration stopped inside the photon orbit. Sampling can overestimate the minimum by roughly (half-step)²/(2r), about half a part in ten thousand at the chosen pace.

Nonfinite state returns NaN, including a ray placed at infinity: such a ray cannot be marched, and infinity would imply it came no closer.

This method is moving to Slayer with the march; see the package doc.

func (Hole) DeflectionAngle

func (hole Hole) DeflectionAngle(
	ray Ray, farRadius float64, steps int,
) float64

DeflectionAngle returns the angle from the initial spatial velocity to the escaped velocity, in radians from zero to pi. Both endpoints must be far enough away for spatial coordinates to approximate flat-space directions.

This is the endpoint angle, not accumulated winding: a ray circling more than halfway is still reported in [0, pi]. A ray that does not escape returns NaN. This marching helper is part of the proposed move to Slayer.

func (Hole) Dropped

func (hole Hole) Dropped(position Vec3) Ray

Dropped releases a unit-mass body from rest at an arbitrary point and coordinate time zero. Falling is the x-axis version.

func (Hole) Energy

func (hole Hole) Energy(ray Ray) float64

Energy returns conserved energy, minus the time component of momentum.

func (Hole) Falling

func (hole Hole) Falling(initialRadius float64) Ray

Falling drops a unit-mass body from rest on the x axis for integration by Advance. initialRadius is the Kerr–Schild radius; with spin, the corresponding x coordinate is sqrt(radius² + A²).

func (Hole) FrameOf

func (hole Hole) FrameOf(position Vec3, observer Vec4) Frame

FrameOf constructs a tetrad at position for the supplied observer four-velocity.

func (Hole) Hamiltonian

func (hole Hole) Hamiltonian(ray Ray) float64

Hamiltonian returns H = g^{ab}p_a p_b / 2. It is conserved along a geodesic: zero for light and -1/2 for a unit-mass body.

func (Hole) Horizon

func (hole Hole) Horizon() float64

Horizon returns the outer horizon radius, 2M at zero spin.

func (Hole) Hovering

func (hole Hole) Hovering(ray Ray) bool

Hovering identifies incoming rays whose backward time rate exceeds the configured ratio to conserved energy. Integration would approach the horizon origin without reaching it; the marcher treats it as black. Outgoing light with a large forward rate is not hovering.

This stopping policy is part of the proposed move to Slayer.

func (Hole) ISCO

func (hole Hole) ISCO(prograde bool) float64

ISCO is the innermost stable circular orbit, prograde or retrograde: 6M at zero spin, down to M prograde and up to 9M retrograde at full spin, by Bardeen, press and teukolsky's equation 2.21, read on 2026-10-31 (numbers.go cites the paper).

func (Hole) ImpactParameter

func (hole Hole) ImpactParameter(ray Ray) float64

ImpactParameter returns total angular momentum divided by energy: the distant straight-line miss distance without deflection. It includes components along and across the spin axis.

At zero spin it is conserved and capture occurs below Shadow. With spin it describes the distant sky position, not a universal capture threshold; Lz/E and Carter/E² determine capture separately. Zero energy returns infinity.

func (Hole) Inverse

func (hole Hole) Inverse(position Vec3) Mat4

Inverse is the contravariant metric at a point: flat minus scalar * vector * vector with vector raised, which the Kerr-schild form gives exactly.

func (Hole) Lower

func (hole Hole) Lower(position Vec3, vector Vec4) Vec4

Lower is a contravariant vector made covariant with the metric at a point.

func (Hole) Lz

func (hole Hole) Lz(ray Ray) float64

Lz returns conserved angular momentum about the spin axis.

func (Hole) March

func (hole Hole) March(ray Ray, farRadius float64, steps int) (Ray, Fate)

March integrates until a ray escapes farRadius, is captured, or exhausts its step budget. The returned ray is the state at stopping, for either forward light or backward-traced incoming light.

An inward physical ray is captured once it lies inside the photon orbit associated with its Lz/E and cannot return. At zero spin this can stop at 3M, well outside the horizon; the returned endpoint is not a horizon intersection.

Forward light inside the horizon is captured immediately. Outward light just outside can escape. An incoming ray inside the horizon is instead allowed to trace back to light that fell in after the observer; hovering supplies its separate stopping condition.

Steps use PaceIn and fourth-order Runge–Kutta. A step crossing the far radius is retained, so the endpoint may overshoot. Nonfinite state is stuck immediately.

March is included in the proposed move of rendering policy to Slayer.

func (Hole) Mass

func (hole Hole) Mass() float64

Mass returns the geometric mass M, which sets the length scale.

func (Hole) Metric

func (hole Hole) Metric(position Vec3) Mat4

Metric is the covariant metric at a point: flat plus scalar * vector * vector.

func (Hole) Normal

func (hole Hole) Normal(position Vec3) Vec4

Normal returns the four-velocity normal to the chart’s constant-time slices. It has zero angular momentum, follows frame dragging, and exists outside the horizon, including the ergosphere.

It is not stationary: even without spin it falls inward, slowly far away and faster nearby. Use Static where available for an object held at fixed coordinates.

func (Hole) Null

func (hole Hole) Null(position Vec3, frame Frame, direction Vec3) Ray

Null constructs outgoing light in a local frame direction, ignoring the direction’s length. The observer’s time axis plus the normalized spatial direction is lowered to covariant momentum.

The ray begins at coordinate time zero and has unit energy as measured by that observer.

func (Hole) PaceIn

func (hole Hole) PaceIn(ray Ray) float64

PaceIn sizes a ray’s step so coordinate time changes by the chosen fraction of its current radius. Far away, this also gives an energy-independent spatial step.

Near the horizon, an incoming ray traced toward its distant-past origin can have unbounded time rate and momentum. The step shrinks to avoid overshooting that limit. Ingoing physical light crossing the horizon keeps a finite step in this chart.

PaceIn uses marching choices and belongs to the proposed move of rendering policy to Slayer.

func (Hole) PhotonOrbit

func (hole Hole) PhotonOrbit(prograde bool) float64

PhotonOrbit is the radius of the circular photon orbit in the equator, prograde or retrograde: 3M at zero spin, down to M prograde and up to 4M retrograde at full spin, by Bardeen, press and teukolsky's equation 2.18, read on 2026-10-31 (numbers.go cites the paper).

Every other photon orbit, the ones that leave the equator, lies between the two.

func (Hole) PhotonSphere

func (hole Hole) PhotonSphere() float64

PhotonSphere returns the Schwarzschild reference radius 3M. For a spinning hole, PhotonOrbit gives the distinct prograde and retrograde equatorial radii.

func (Hole) Radius

func (hole Hole) Radius(position Vec3) float64

Radius returns the Kerr–Schild radial coordinate: the Schwarzschild radius coordinate at zero spin, or the oblate coordinate with spin. It is zero on the disc bounded by the ring singularity.

Very near that disc, cancellation can also round the result to zero. The marcher avoids relying on this region: bodies stop at the inner horizon, while light uses its capture and horizon stopping rules.

func (Hole) Raise

func (hole Hole) Raise(position Vec3, covector Vec4) Vec4

Raise is a covariant vector made contravariant with the inverse at a point.

func (Hole) Seen

func (hole Hole) Seen(frame Frame, ray Ray) Vec3

Seen returns the unit direction from which a frame’s observer sees the ray’s light, including aberration. Spatial tetrad components are normalized with the sign appropriate to the momentum convention.

Physical photon momentum is reversed to point toward its origin. Arriving already negates that momentum, so it needs no reversal. The time contraction distinguishes them; Seen therefore reverses Arriving’s construction of a sky direction.

func (Hole) Shadow

func (hole Hole) Shadow() float64

Shadow returns the Schwarzschild shadow impact parameter √27 M for a distant observer. It is not a rotating-hole shadow contour.

func (Hole) Spin

func (hole Hole) Spin() float64

Spin returns A = J/M in the same length unit as Mass. The dimensionless spin is A/M.

func (Hole) Static

func (hole Hole) Static(position Vec3) Vec4

Static returns the four-velocity of an observer held at fixed coordinates, normalizing the time axis. It returns NaN components where such an observer cannot exist.

For a spinning hole this boundary is the ergosurface: 2M in the equatorial plane and the horizon on the axis. At zero spin it is the horizon everywhere.

func (Hole) Step

func (hole Hole) Step(ray Ray, stepSize float64) Ray

Step advances by one fourth-order Runge–Kutta interval in the affine parameter, using the caller’s step size.

func (Hole) Velocity

func (hole Hole) Velocity(ray Ray) Vec4

Velocity raises covariant momentum to give dx/dlambda along the geodesic.

type Mat4

type Mat4 [dimensions][dimensions]float64

Mat4 stores a metric or its inverse in (t, x, y, z) row and column order.

type Ray

type Ray struct {
	// contains filtered or unexported fields
}

Ray stores spacetime position and covariant momentum. Light has null momentum; the massive-body model uses timelike unit mass.

func NewRay

func NewRay(position, momentum Vec4) Ray

NewRay stores a position and covariant momentum without validating their physical relation. Nonfinite state is allowed to propagate as an invalid ray; March reports it as stuck.

func (Ray) Momentum

func (ray Ray) Momentum() Vec4

Momentum returns the covariant momentum.

func (Ray) Position

func (ray Ray) Position() Vec4

Position returns (t, x, y, z).

func (Ray) Space

func (ray Ray) Space() Vec3

Space returns the spatial position.

type RayClassification

type RayClassification int

RayClassification describes the outcome assigned by ClassifyRay.

const (
	RayEscapes RayClassification = iota // got far away
	RayPlunges                          // was captured
	// did neither in the steps it was given
	RayCirculates
)

The classifications.

type RayStep

type RayStep struct {
	// contains filtered or unexported fields
}

RayStep records a stepped ray and its diagnostic invariants. Energy, axial angular momentum, Carter constant, and Hamiltonian should remain conserved; numerical drift measures stepping error.

func (RayStep) AngularMomentum

func (step RayStep) AngularMomentum() float64

AngularMomentum is the angular momentum about the spin axis that the ray keeps.

func (RayStep) CarterConstant

func (step RayStep) CarterConstant() float64

CarterConstant is the Carter constant the ray keeps.

func (RayStep) Energy

func (step RayStep) Energy() float64

Energy is the energy the ray keeps.

func (RayStep) Hamiltonian

func (step RayStep) Hamiltonian() float64

Hamiltonian is the ray's H, which a geodesic keeps.

func (RayStep) Momentum

func (step RayStep) Momentum() Vec4

Momentum is the ray's covariant momentum after the step.

func (RayStep) Position

func (step RayStep) Position() Vec4

Position is the ray's place in spacetime after the step.

func (RayStep) Radius

func (step RayStep) Radius() float64

Radius is the ray's Kerr-schild radius after the step.

func (RayStep) Redshift

func (step RayStep) Redshift() float64

Redshift returns energy at the stationary camera divided by energy for a stationary emitter at the current point. It is NaN before a camera is set or where a stationary emitter cannot exist.

type ShaderParams

type ShaderParams struct {
	// contains filtered or unexported fields
}

ShaderParams stores float32 geometry and camera constants. Its 96-byte shader layout is five scalars, three packed position values, and a 4×4 frame beginning at byte 32. Bytes serializes that contract.

func (ShaderParams) Bytes

func (params ShaderParams) Bytes() []byte

Bytes serializes the 96-byte shader layout in little-endian order: five scalars, three position values, then four frame rows.

func (ShaderParams) CameraFrame

func (params ShaderParams) CameraFrame() [dimensions][dimensions]float32

CameraFrame is the camera's tetrad, one vector to a row, the observer's four-velocity first.

func (ShaderParams) CameraPosition

func (params ShaderParams) CameraPosition() [cameraPlaces]float32

CameraPosition is the camera's place in space.

func (ShaderParams) Horizon

func (params ShaderParams) Horizon() float32

Horizon is the outer horizon's radius.

func (ShaderParams) Mass

func (params ShaderParams) Mass() float32

Mass is the hole's mass.

func (ShaderParams) PhotonSphere

func (params ShaderParams) PhotonSphere() float32

PhotonSphere is the radius of the photon sphere of a hole with no spin.

func (ShaderParams) Shadow

func (params ShaderParams) Shadow() float32

Shadow is the radius of the shadow of a hole with no spin.

func (ShaderParams) Spin

func (params ShaderParams) Spin() float32

Spin is the hole's spin.

type Vec3

type Vec3 struct {
	// contains filtered or unexported fields
}

Vec3 stores a spatial position or direction with named component accessors. Construction permits NaN so invalid or undefined positions can propagate explicitly.

func NewVec3

func NewVec3(x, y, z float64) Vec3

NewVec3 is the point or direction with the parts x, y and z.

func (Vec3) AlongX

func (vec Vec3) AlongX() float64

AlongX is the part along the x axis.

func (Vec3) AlongY

func (vec Vec3) AlongY() float64

AlongY is the part along the y axis.

func (Vec3) AlongZ

func (vec Vec3) AlongZ() float64

AlongZ is the part along the z axis, the spin axis of a hole.

type Vec4

type Vec4 struct {
	// contains filtered or unexported fields
}

Vec4 stores a spacetime point or vector, covariant or contravariant as specified by the caller. Component order is (t, x, y, z).

The four-field struct lets the compiler keep values in registers within and between calls. In the measured array version, memory traffic accounted for more than half the cost of a step.

Named accessors expose private components. NaN values are allowed to represent undefined states.

func NewVec4

func NewVec4(time, x, y, z float64) Vec4

NewVec4 is the vector with the parts time, x, y and z.

func (Vec4) AlongX

func (vec Vec4) AlongX() float64

AlongX is the part along the x axis.

func (Vec4) AlongY

func (vec Vec4) AlongY() float64

AlongY is the part along the y axis.

func (Vec4) AlongZ

func (vec Vec4) AlongZ() float64

AlongZ is the part along the z axis, the spin axis of a hole.

func (Vec4) Space

func (vec Vec4) Space() Vec3

Space is the part in space of a point or a vector in spacetime.

func (Vec4) Time

func (vec Vec4) Time() float64

Time is the part along time.

Jump to

Keyboard shortcuts

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