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 ¶
- func Dot(covector, vector Vec4) float64
- func ErrNothingStill() error
- func Shift(momentumAtEye, observer, momentumAtEmitter, emitter Vec4) float64
- type Fate
- type Frame
- type GPUBlackHole
- func (gb *GPUBlackHole) Hole() Hole
- func (gb *GPUBlackHole) SetCamera(position Vec3) error
- func (gb *GPUBlackHole) ShaderParams() ShaderParams
- func (gb *GPUBlackHole) StepRay(ray *Ray, stepSize float64) RayStep
- func (gb *GPUBlackHole) StepRaysBatch(reports []RayStep, rays []Ray, stepSize float64) []RayStep
- type Hole
- func (hole Hole) Advance(ray Ray, properTime float64) (Ray, bool)
- func (hole Hole) Arriving(position Vec3, frame Frame, direction Vec3) Ray
- func (hole Hole) Carter(ray Ray) float64
- func (hole Hole) Circular(position Vec3) Vec4
- func (hole Hole) ClassifyRay(ray Ray) RayClassification
- func (hole Hole) ClosestApproach(ray Ray, steps int) float64
- func (hole Hole) DeflectionAngle(ray Ray, farRadius float64, steps int) float64
- func (hole Hole) Dropped(position Vec3) Ray
- func (hole Hole) Energy(ray Ray) float64
- func (hole Hole) Falling(initialRadius float64) Ray
- func (hole Hole) FrameOf(position Vec3, observer Vec4) Frame
- func (hole Hole) Hamiltonian(ray Ray) float64
- func (hole Hole) Horizon() float64
- func (hole Hole) Hovering(ray Ray) bool
- func (hole Hole) ISCO(prograde bool) float64
- func (hole Hole) ImpactParameter(ray Ray) float64
- func (hole Hole) Inverse(position Vec3) Mat4
- func (hole Hole) Lower(position Vec3, vector Vec4) Vec4
- func (hole Hole) Lz(ray Ray) float64
- func (hole Hole) March(ray Ray, farRadius float64, steps int) (Ray, Fate)
- func (hole Hole) Mass() float64
- func (hole Hole) Metric(position Vec3) Mat4
- func (hole Hole) Normal(position Vec3) Vec4
- func (hole Hole) Null(position Vec3, frame Frame, direction Vec3) Ray
- func (hole Hole) PaceIn(ray Ray) float64
- func (hole Hole) PhotonOrbit(prograde bool) float64
- func (hole Hole) PhotonSphere() float64
- func (hole Hole) Radius(position Vec3) float64
- func (hole Hole) Raise(position Vec3, covector Vec4) Vec4
- func (hole Hole) Seen(frame Frame, ray Ray) Vec3
- func (hole Hole) Shadow() float64
- func (hole Hole) Spin() float64
- func (hole Hole) Static(position Vec3) Vec4
- func (hole Hole) Step(ray Ray, stepSize float64) Ray
- func (hole Hole) Velocity(ray Ray) Vec4
- type Mat4
- type Ray
- type RayClassification
- type RayStep
- func (step RayStep) AngularMomentum() float64
- func (step RayStep) CarterConstant() float64
- func (step RayStep) Energy() float64
- func (step RayStep) Hamiltonian() float64
- func (step RayStep) Momentum() Vec4
- func (step RayStep) Position() Vec4
- func (step RayStep) Radius() float64
- func (step RayStep) Redshift() float64
- type ShaderParams
- func (params ShaderParams) Bytes() []byte
- func (params ShaderParams) CameraFrame() [dimensions][dimensions]float32
- func (params ShaderParams) CameraPosition() [cameraPlaces]float32
- func (params ShaderParams) Horizon() float32
- func (params ShaderParams) Mass() float32
- func (params ShaderParams) PhotonSphere() float32
- func (params ShaderParams) Shadow() float32
- func (params ShaderParams) Spin() float32
- type Vec3
- type Vec4
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dot ¶
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 ¶
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Dropped releases a unit-mass body from rest at an arbitrary point and coordinate time zero. Falling is the x-axis version.
func (Hole) Falling ¶
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 ¶
FrameOf constructs a tetrad at position for the supplied observer four-velocity.
func (Hole) Hamiltonian ¶
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) Hovering ¶
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 ¶
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 ¶
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 ¶
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) March ¶
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) Normal ¶
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 ¶
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 ¶
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 ¶
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 ¶
PhotonSphere returns the Schwarzschild reference radius 3M. For a spinning hole, PhotonOrbit gives the distinct prograde and retrograde equatorial radii.
func (Hole) Radius ¶
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) Seen ¶
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 ¶
Shadow returns the Schwarzschild shadow impact parameter √27 M for a distant observer. It is not a rotating-hole shadow contour.
func (Hole) Spin ¶
Spin returns A = J/M in the same length unit as Mass. The dimensionless spin is A/M.
func (Hole) Static ¶
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.
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.
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 ¶
AngularMomentum is the angular momentum about the spin axis that the ray keeps.
func (RayStep) CarterConstant ¶
CarterConstant is the Carter constant the ray keeps.
func (RayStep) Hamiltonian ¶
Hamiltonian is the ray's H, which a geodesic keeps.
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) 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.
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.
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.