hole

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 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 is the maths of a black hole for a renderer: a kerr hole in kerr-schild form, null and timelike geodesics marched by hamilton's equations, the quantities a geodesic keeps, the redshift between two observers, and the frame of a camera falling in.

It imports nothing but the standard library, so the relativity can leave; what it does not know is anything about light or pictures.

One file leans toward a renderer, gpu.go: the hole and a camera as the float32 constants a shader takes, and a step that reports what a ray keeps, to hold a shader's own steps against. There is no GPU in it and nothing of a picture.

Units: G and c are one, and a hole of mass M has its lengths in M. The signature is minus, plus, plus, plus; a point is (t, x, y, z) and a momentum is covariant.

Where its numbers come from. The Kerr-Schild form, the radii of a Kerr hole and the runge-kutta step are defined by their formulas, and numbers.go says by which.

The march's tolerances are choices, not physics. They are in choices.json, built in, each with what it says and who picked it.

The tests' own numbers are in testdata/hole.json, each with where it came from.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(covector, vector Vec4) float64

Dot is the inner product of a covariant and a contravariant vector.

func ErrNothingStill

func ErrNothingStill() error

ErrNothingStill is SetCamera's refusal of a point where no observer can be held still: inside the ergosurface of a spinning hole, or inside the horizon of any.

It is a function so that it cannot be changed behind a caller's back; errors.Is finds it in what SetCamera returns.

func Shift

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

Shift is the ratio of a photon's energy at the eye to its energy at the emitter, along a ray: its momentum at the eye on the observer's four-velocity there, over its momentum at the emitter on the emitter's four-velocity there.

Over one the light arrives bluer, under one redder; doppler beaming and the hole's own redshift are both in it.

The momentum is not the same at the two ends: a ray keeps only its time part. One momentum serves at both ends only where that end's observer is still, with nothing but a time part to its velocity.

Types

type Fate

type Fate int

Fate is how a march ended.

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 at a point: the observer's four-velocity first, then three spatial axes square to it and to one another in the metric, made from the coordinate axes by gram and schmidt, x first.

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 a camera held still beside it, as a shader wants them: ShaderParams is the two as float32 constants, and StepRay steps a ray on the processor and reports what it keeps, for holding a shader's own steps against.

There is no GPU in it. It steps one ray at a time on one core, and its batches are loops. SetCamera changes it, so it is not to be shared between goroutines while one of them sets the camera.

func NewGPUBlackHole

func NewGPUBlackHole(mass, spin float64) *GPUBlackHole

NewGPUBlackHole is a hole of a mass and a spin with no camera yet, or nil if they are no hole's, as NewHole says. SetCamera gives it one.

func (*GPUBlackHole) Hole

func (gb *GPUBlackHole) Hole() Hole

Hole is the hole itself, for everything a Hole can be asked: its metric, its marches, what its rays keep.

func (*GPUBlackHole) SetCamera

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

SetCamera puts a camera held still at a point and works out its frame, once, for every step and every ShaderParams after it.

Where nothing is still there is no such camera: it answers ErrNothingStill and leaves the camera where it was.

func (*GPUBlackHole) ShaderParams

func (gb *GPUBlackHole) ShaderParams() ShaderParams

ShaderParams is the hole and the camera as constants for a shader. Before a camera is set the camera's part is all nought.

func (*GPUBlackHole) StepRay

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

StepRay takes a ray one runge-kutta step of a size, in place, and reports where it now is and what it keeps there.

The report costs more than twice what the step does, so a march that does not read it is better made with Hole's March or Step.

func (*GPUBlackHole) StepRaysBatch

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

StepRaysBatch takes each ray of a slice one step of a size, in place, and reports on each in the same order.

The reports go into the slice handed in when it is long enough, so a caller that keeps handing back what this returns allocates once; nil will do for the first call.

type Hole

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

Hole is a black hole: its mass M and its spin A, the angular momentum per unit mass, from nought for schwarzschild up to just under M. The spin axis is z, and the hole turns from x toward y.

Only NewHole makes one, and it makes only a hole the other methods are right for.

func NewHole

func NewHole(mass, spin float64) *Hole

NewHole is the hole of a mass and a spin, or nil if they are no hole's: a finite mass above nought, and a spin from nought to just under it.

A spin at or above the mass is no black hole, since it has no horizon. A spin below nought is the same hole seen from below: turn z about instead, since ISCO and Circular take the spin's sense to be the one above.

A mass or a spin that is not a number is refused, as is an infinite mass.

func (Hole) Advance

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

Advance carries a body's geodesic on by a proper time and says whether it is inside the horizon. Its steps are half the pace at the nearer of its radius and its distance from the ring: close to the ring the hole changes over that distance, which is much the shorter.

Inside means inside the horizon itself, to the last digit: the margin a march of light stops at is for rays and is not used here.

A body is carried no further than the chart goes.

It stops, inside, with the rest of its proper time unspent, within choices.json's singularity margin of the ring or of the disc the ring spans, and at the inner horizon of a spinning hole.

Past the inner horizon a body off the equator turns back outward, and its way out is not in these coordinates. The pace goes to nought at the singularity, and a step taken any nearer than the margin lands in the flat space the kernel falls back to at nought radius.

Its steps are choices.json's advance share of the pace: a body's proper time is short beside a ray's parameter near the hole, so its steps are the finer.

func (Hole) Arriving

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

Arriving is the ray of light arriving at a point from the direction direction as the observer with tetrad frame sees it, set up to be marched forward in its parameter, which runs backward in time: a picture is traced from the eye.

Its momentum is the arriving photon's negated, so the energies an observer measures along it, Dot(P, u), come out positive. Round a still hole it runs the path of the ray of Null leaving toward direction; round a spinning one the two part, since the dragging turns them.

func (Hole) Carter

func (hole Hole) Carter(ray Ray) float64

Carter is the carter constant, which a geodesic keeps beside E and Lz. In the angle theta that the kerr-schild coordinates share with boyer and lindquist's, z = R cos theta, it is

Q = p_theta^2 + cos^2 theta (A^2 (mu^2 - E^2) + Lz^2 / sin^2 theta)

with mu^2 minus twice H: nought for light, one for a body of unit mass. At nought spin it is the square of the angular momentum less Lz squared. On the disc inside the ring, where R is nought, it is not a number.

func (Hole) Circular

func (hole Hole) Circular(position Vec3) Vec4

Circular is the four-velocity of matter going round the hole on a circle at a point, prograde, as a thin disc's does: kepler's rate with the hole's correction, which is the same rate by the clock at infinity in these coordinates as in boyer and lindquist's.

Inside the prograde photon orbit nothing goes round at that rate, and the answer is not a number. It can be had inside the ergosphere, where Static cannot.

func (Hole) ClassifyRay

func (hole Hole) ClassifyRay(ray Ray) RayClassification

ClassifyRay says whether a ray or a body escapes, plunges into the hole or circulates, by marching it and seeing where it goes.

It escapes on getting choices.json's far factor times its starting radius out, or its far floor in M if that is further; it circulates if it has done neither after its classify steps.

A bound body whose orbit reaches past that radius is classed as escaping, and a ray that is not a number as circulating.

func (Hole) ClosestApproach

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

ClosestApproach is the least radius a ray comes to: it is marched, as March marches it, until it has turned back outward, been captured, or taken all its steps, and the least radius it stood at, the last included, is the answer.

A ray on its way out from the start answers the radius it started at, and a captured ray the radius it was given up at, which is inside its photon orbit and says no more than that.

The answer is the least of the radii stepped at, so it is over by up to the square of half a step over twice the radius: half a part in ten thousand. For a ray that is not a number it is not a number, at once.

func (Hole) DeflectionAngle

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

DeflectionAngle is the angle between the way a ray sets out and the way it leaves past the far radius, in radians from nought to pi: how far the hole bent it, in whatever plane it was bent.

The two ways are the ray's velocity in space, which is where it is going only where space is flat, so the start and the far radius MUST both be far from the hole.

A ray that goes more than half round reads as the angle between its two ways, not as its turning. A ray that does not escape has no deflection, and the answer is not a number.

func (Hole) Dropped

func (hole Hole) Dropped(position Vec3) Ray

Dropped is a body let go from rest at a point, at time nought, as a camera is that falls in from anywhere; Falling is the same on the x axis.

func (Hole) Energy

func (hole Hole) Energy(ray Ray) float64

Energy is the energy a geodesic keeps, minus the time momentum.

func (Hole) Falling

func (hole Hole) Falling(initialRadius float64) Ray

Falling is a body let go from rest at a radius on the x axis, as a camera falling into the hole: its geodesic from there, timelike with unit mass, marched by Advance.

The radius is R, the kerr-schild one; round a spinning hole that point's x is the root of R squared plus A squared.

func (Hole) FrameOf

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

FrameOf is the tetrad of an observer with four-velocity observer at a point.

func (Hole) Hamiltonian

func (hole Hole) Hamiltonian(ray Ray) float64

Hamiltonian is hamilton's function, half the inverse metric on the momentum: nought along a null ray and minus a half along a body of unit mass, kept along any geodesic.

func (Hole) Horizon

func (hole Hole) Horizon() float64

Horizon is the outer horizon's radius: 2M at nought spin.

func (Hole) Hovering

func (hole Hole) Hovering(ray Ray) bool

Hovering is whether an arriving ray has come from the hole's edge: its time runs away backward, choices.json's hover ratio times its energy's, and the march would never get there. Such a ray is black.

Light leaving the edge outward has its time run as fast forward, and is not hovering: it gets out.

func (Hole) ISCO

func (hole Hole) ISCO(prograde bool) float64

ISCO is the innermost stable circular orbit, prograde or retrograde: 6M at nought 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 is how far from the hole's centre a ray of light from far away would pass were it not bent: its angular momentum over its energy, the whole angular momentum, across the spin axis and about it, so the answer is the same in whatever plane the ray lies.

Round a still hole the ray keeps it, and is captured when it is less than Shadow.

Round a spinning one it is the ray's distance from the centre on the sky of whoever is far along it, right in the limit of far away; there is no one radius to hold it against there, since capture is decided by Lz over E and Carter over E squared apart.

A ray with no energy has none, and the answer is infinite.

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 is the angular momentum about the spin axis a geodesic keeps.

func (Hole) March

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

March carries a ray until it is past far from the hole, captured, or out of steps, and says which; the ray handed back is where it stopped. It marches a leaving ray forward and an arriving ray back alike.

A ray is captured as soon as it cannot come back: when it is inside the photon orbit that has its own angular momentum and is still going inward.

For light seen from outside that is well short of the horizon, three M round a still hole, and the ray is handed back from there; that pixel is black.

Light sent forward from inside the horizon is always going inward, and is captured where it starts. Light sent outward from just outside the horizon is not captured, however near: it gets out.

An arriving ray is not captured for being inside the horizon: an eye that has fallen through still sees the light that fell in after it, and March carries that light back out to where it came from. Inside the horizon an arriving ray is captured when it is found hovering.

Each step is a runge-kutta step of PaceIn's size, and a step that would cross the far radius is taken anyway, so the ray may end a little past it. A ray that is not a number is stuck at once.

func (Hole) Mass

func (hole Hole) Mass() float64

Mass is the hole's mass M, which is also its unit of length.

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 is the four-velocity of the observer normal to the chart's slices of constant time at a point: it carries no angular momentum, is carried round by the dragging and nothing else, and exists everywhere outside the horizon, ergosphere included, where Static does not.

It is not still: in this chart it falls inward, slowly far out and faster close in, even round a still hole. Where Static exists, it is the one to prefer for a thing held in place.

func (Hole) Null

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

Null is a ray of light leaving a point in the direction direction as the observer with tetrad frame sees it: direction is a direction in the observer's own space, its length not used.

The ray's momentum is the observer's time axis plus the unit direction along the spatial axes, lowered, so that it is null.

The ray starts at time nought, and its energy as that observer measures it is one.

func (Hole) PaceIn

func (hole Hole) PaceIn(ray Ray) float64

PaceIn is the step for a ray where it stands: the step in which its time moves on, or back, by choices.json's time share of its radius.

Far from the hole that is the same share of the radius in distance too, whatever the light's energy, since a photon's energy has no say in where it goes.

Near the hole's edge it is less, and for an arriving ray that came from the edge it shrinks without end: that light left the edge in the far past, its time runs away as the ray comes to it, and so does its momentum, which a step sized by distance would overshoot.

A ray crossing the horizon the other way, light that fell in, keeps its time in hand and crosses at a full step, as the chart lets.

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 nought 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 is the radius of the circular photon orbit of a hole with no spin, 3M; with spin the orbits split prograde and retrograde and this is the schwarzschild value. PhotonOrbit is the two.

func (Hole) Radius

func (hole Hole) Radius(position Vec3) float64

Radius is the kerr-schild radius at a point: the schwarzschild r at nought spin, and the oblate coordinate that reaches the ring singularity with spin.

On the disc the ring spans it is nought, and within a hair of that disc it rounds to nought as well, being there the difference of two numbers that agree to all their digits. No march comes there: a body is stopped at the inner horizon and light at the outer.

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 is the direction an observer with tetrad frame sees a ray's light come from, a unit direction in the observer's own space, which is where the light appears on that observer's sky after aberration.

It is the momentum's parts along the spatial axes, normalised, and turned to face the way the light came: about, for a photon's own momentum, and not at all for an arriving ray's, which Arriving has negated already.

The momentum's part along the observer's time axis says which it is, below nought for a photon and above for an arriving ray, so Seen of the ray Arriving built from a direction is that direction.

func (Hole) Shadow

func (hole Hole) Shadow() float64

Shadow is the radius of the shadow a hole with no spin casts on the sky of a far observer, root twenty-seven M: the impact parameter at which a ray is just captured.

func (Hole) Spin

func (hole Hole) Spin() float64

Spin is the hole's spin A, the angular momentum per unit mass, in the same unit as the mass.

func (Hole) Static

func (hole Hole) Static(position Vec3) Vec4

Static is the four-velocity of an observer held still at a point: the time axis scaled to unit length.

Nothing is still inside the ergosurface, where the hole's spin drags everything round with it: on the equator that is inside two M at any spin, on the axis it is the horizon, and at nought spin it is the horizon everywhere. There the answer is not a number.

func (Hole) Step

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

Step is one runge-kutta step of the affine parameter.

func (Hole) Velocity

func (hole Hole) Velocity(ray Ray) Vec4

Velocity is the contravariant velocity along the geodesic, dx by the affine parameter: the inverse metric on the momentum.

type Mat4

type Mat4 [dimensions][dimensions]float64

Mat4 is a metric or its inverse, by row and column in the order t, x, y, z.

type Ray

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

Ray is a geodesic's state: where it is in spacetime and its covariant momentum. For light the momentum is null; for a body it is timelike with unit mass.

func NewRay

func NewRay(position, momentum Vec4) Ray

NewRay is a geodesic at a point in spacetime with a covariant momentum. Any two vectors make one; a ray whose parts are not numbers is stuck at once when marched.

func (Ray) Momentum

func (ray Ray) Momentum() Vec4

Momentum is the ray's covariant momentum.

func (Ray) Position

func (ray Ray) Position() Vec4

Position is where the ray is in spacetime, (t, x, y, z).

func (Ray) Space

func (ray Ray) Space() Vec3

Space is the ray's point in space.

type RayClassification

type RayClassification int

RayClassification is where a ray or a body ends up, as ClassifyRay says it.

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 is a ray after a step and what it keeps there: a geodesic holds Energy, AngularMomentum, CarterConstant and Hamiltonian fixed, so their drift from step to step is the stepping's 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 is the photon's energy at the camera over its energy as an emitter held still where the ray now is would have it. It is not a number before a camera is set, and where nothing is still.

type ShaderParams

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

ShaderParams is the hole and the camera as constants for a shader, in float32, which is what a shader has.

Its layout is a contract with the shader's own struct: five floats, a packed three, and a four by four at byte 32, 96 bytes in all. Bytes is that layout.

func (ShaderParams) Bytes

func (params ShaderParams) Bytes() []byte

Bytes is the constants as the shader's struct holds them: little endian, the five scalars first, then the camera's position, then the frame a row at a time. It is 96 bytes.

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 is a point or a direction in space.

Its parts are private so that its places are said by name, AlongX, AlongY and AlongZ, and not by number.

Any three numbers make one, a number that is not a number among them: that is how a place with no value is carried.

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 is a point in spacetime, or a covariant or contravariant vector there; which one is said where it is used. Its places are Time, AlongX, AlongY and AlongZ, in that order.

It is a struct of four numbers and not an array because the compiler keeps a struct of up to four numbers in registers, in a function and between functions, and sends an array through memory; with arrays that traffic was more than half the cost of a step.

Its parts are private so that its places are said by name. Any four numbers make one, a number that is not a number among them: that is how a place with no value is carried.

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