struct

Kozai::Vector3

Inherits Struct < Value < Object

A three-component vector of Float64, used for every position, velocity and direction in the library.

This is a struct on purpose. Pass prediction over a week for a hundred satellites runs to millions of propagator steps, and each step produces several intermediate vectors. As a class, every one of those would be a heap allocation and the garbage collector would dominate the run; as a value type they live on the stack and cost nothing. spec/allocation_spec.cr asserts that the hot loop allocates zero bytes, which is only achievable this way.

Every operation returns a new value; nothing here mutates in place.

Units are whatever the caller is working in — the propagator produces kilometres and km/s, Frames and Observer keep that convention.

Constructors

new(x : Float64, y : Float64, z : Float64)

Creates a vector from its three components.

Source
zero

The zero vector.

Source

Instance methods

*(scalar : Float64) : Vector3

Multiplication by a scalar.

Source
+(other : Vector3) : Vector3

Component-wise sum.

Source
-(other : Vector3) : Vector3

Component-wise difference.

Source
-

Negation.

Source
/(scalar : Float64) : Vector3

Division by a scalar.

Source
angle_to(other : Vector3) : Float64

Angle to other, in radians, in the range 0..PI.

Returns 0.0 if either vector has zero length.

Source
cross(other : Vector3) : Vector3

Cross product with other, following the right-hand rule.

Source
distance_to(other : Vector3) : Float64

Distance to other.

Source
dot(other : Vector3) : Float64

Dot product with other.

Source
finite?

Whether every component is finite.

A propagator that has diverged reports itself through SGP4::ErrorCode, but pathological elements can still produce infinities in downstream geometry; this is the cheap guard for that.

Source
magnitude

Euclidean length.

Source
magnitude_squared

Squared Euclidean length.

Prefer this to #magnitude when only comparing lengths: it skips the square root.

Source
normalize

A unit vector pointing the same way.

Returns Vector3.zero for a zero-length vector rather than producing NaNs, so that callers walking a track do not have to special-case a degenerate step.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
x

First component.

Source
y

Second component.

Source
z

Third component.

Source