types

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

README

types

Fundamental data types and mathematical structures for representing physical quantities in the simulation.

Notes

  • Implements core mathematical types such as Vector3, Quaternion, and Matrix3x3
  • Provides physical state representations (Position, Velocity, Acceleration)
  • Defines specialized types for mass, orientation, and other physical properties
  • Includes methods for vector operations and coordinate transformations
  • Implements quaternion-based rotation calculations for 3D space
  • Supports serialization of types for storage and communication
  • Ensures type safety and consistent units across the simulation
  • Provides utility functions for common mathematical operations

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Acceleration

type Acceleration struct {
	ecs.BasicEntity
	Vec Vector3
}

Acceleration represents a 3D acceleration as a vector

type Event added in v0.5.0

type Event int

Event represents significant simulation milestones.

const (
	None Event = iota
	Liftoff
	Apogee
	Land
	ParachuteDeploy
	Burnout
)

func (Event) String added in v0.5.0

func (e Event) String() string

String returns a string representation of the event.

type Mass

type Mass struct {
	ecs.BasicEntity
	Value float64
}

Mass represents a mass value

type Matrix3x3 added in v0.8.0

type Matrix3x3 struct {
	M11, M12, M13 float64 // Row 1
	M21, M22, M23 float64 // Row 2
	M31, M32, M33 float64 // Row 3
}

Matrix3x3 represents a 3x3 matrix. Components are row-major: M11, M12, M13 are the first row.

func IdentityMatrix added in v0.8.0

func IdentityMatrix() *Matrix3x3

IdentityMatrix returns an identity matrix.

func IdentityMatrix3x3 added in v0.8.0

func IdentityMatrix3x3() Matrix3x3

IdentityMatrix3x3 returns an identity matrix.

func NewMatrix3x3 added in v0.8.0

func NewMatrix3x3(elements []float64) *Matrix3x3

NewMatrix3x3 creates a new matrix from a slice of 9 elements (row-major). Returns nil if the elements slice does not contain exactly 9 values.

func RotationMatrixFromQuaternion added in v0.8.0

func RotationMatrixFromQuaternion(q *Quaternion) *Matrix3x3

RotationMatrixFromQuaternion converts a Quaternion to a 3x3 rotation matrix.

func TransformInertiaBodyToWorld added in v0.8.0

func TransformInertiaBodyToWorld(inertiaBody *Matrix3x3, rotationMatrixBodyToWorld *Matrix3x3) *Matrix3x3

TransformInertiaBodyToWorld transforms an inertia tensor from body frame to world frame. I_world = R * I_body * R_transpose where R is the rotation matrix from body to world.

func (Matrix3x3) Add added in v0.8.0

func (m Matrix3x3) Add(other Matrix3x3) Matrix3x3

Add returns the sum of two matrices (m + other).

func (Matrix3x3) Determinant added in v0.8.0

func (m Matrix3x3) Determinant() float64

Determinant calculates the determinant of the matrix.

func (Matrix3x3) Inverse added in v0.8.0

func (m Matrix3x3) Inverse() *Matrix3x3

Inverse calculates the inverse of the matrix. Returns nil if the matrix is singular (determinant is zero or very close to zero).

func (*Matrix3x3) MultiplyMatrix added in v0.8.0

func (m *Matrix3x3) MultiplyMatrix(other *Matrix3x3) *Matrix3x3

MultiplyMatrix multiplies this matrix by another matrix 'other' (M * other).

func (Matrix3x3) MultiplyScalar added in v0.8.0

func (m Matrix3x3) MultiplyScalar(s float64) Matrix3x3

MultiplyScalar returns the matrix scaled by a scalar.

func (*Matrix3x3) MultiplyVector added in v0.8.0

func (m *Matrix3x3) MultiplyVector(v *Vector3) *Vector3

MultiplyVector multiplies the matrix by a column vector v and returns the resulting vector. result = M * v

func (Matrix3x3) Subtract added in v0.8.0

func (m Matrix3x3) Subtract(other Matrix3x3) Matrix3x3

Subtract returns the difference of two matrices (m - other).

func (*Matrix3x3) Transpose added in v0.8.0

func (m *Matrix3x3) Transpose() *Matrix3x3

Transpose returns the transpose of the matrix.

type Orientation

type Orientation struct {
	ecs.BasicEntity
	Quat Quaternion
}

Orientation represents a 3D orientation

type Position

type Position struct {
	ecs.BasicEntity
	Vec Vector3
}

Position represents a 3D position

type Quaternion

type Quaternion struct {
	X, Y, Z, W float64
}

Quaternion represents a 3D quaternion

func IdentityQuaternion

func IdentityQuaternion() *Quaternion

IdentityQuaternion returns the identity quaternion

func NewQuaternion

func NewQuaternion(x, y, z, w float64) *Quaternion

NewQuaternion creates a new Quaternion

func (*Quaternion) Add

func (q *Quaternion) Add(q2 *Quaternion) *Quaternion

Add adds two quaternions together

func (*Quaternion) Conjugate

func (q *Quaternion) Conjugate() *Quaternion

Conjugate returns the conjugate of the quaternion

func (*Quaternion) Integrate

func (q *Quaternion) Integrate(omega Vector3, dt float64) *Quaternion

Integrate increments q by the angular velocity (radians/sec) over dt

func (*Quaternion) Inverse added in v0.8.0

func (q *Quaternion) Inverse() *Quaternion

Inverse returns the inverse of the quaternion. For a unit quaternion (which orientation quaternions should be after normalization), the inverse is its conjugate.

func (*Quaternion) IsIdentity

func (q *Quaternion) IsIdentity() bool

IsIdentity checks if the quaternion is the identity quaternion

func (*Quaternion) Magnitude

func (q *Quaternion) Magnitude() float64

Magnitude returns the sum of squares of the quaternion's components

func (*Quaternion) Multiply

func (q *Quaternion) Multiply(q2 *Quaternion) *Quaternion

Multiply multiplies two quaternions together

func (*Quaternion) Normalize

func (q *Quaternion) Normalize() *Quaternion

Normalize normalizes a quaternion

func (*Quaternion) RotateVector

func (q *Quaternion) RotateVector(v *Vector3) *Vector3

RotateVector rotates a vector v by the quaternion q. Ensures q is normalized. Returns original v if q or v is invalid, or if q normalizes to identity.

func (*Quaternion) Scale

func (q *Quaternion) Scale(scalar float64) *Quaternion

Scale scales a quaternion by a scalar

func (*Quaternion) Subtract

func (q *Quaternion) Subtract(q2 *Quaternion) *Quaternion

Subtract subtracts one quaternion from another

type Vector3

type Vector3 struct {
	X, Y, Z float64
}

Vector3 represents a 3D vector

func (Vector3) Add

func (v Vector3) Add(other Vector3) Vector3

Add returns the sum of two vectors INFO: Adding two vectors component-wise.

func (Vector3) DivideScalar

func (v Vector3) DivideScalar(scalar float64) Vector3

DivideScalar returns the vector divided by a scalar INFO: Ensure the scalar is not zero to avoid division by zero.

func (Vector3) Dot added in v0.8.0

func (v Vector3) Dot(other Vector3) float64

Dot returns the dot product of two vectors.

func (Vector3) Magnitude

func (v Vector3) Magnitude() float64

Magnitude returns the length of the vector INFO: Calculating the magnitude as the Euclidean norm.

func (Vector3) MultiplyScalar

func (v Vector3) MultiplyScalar(scalar float64) Vector3

MultiplyScalar returns the vector multiplied by a scalar INFO: Scaling the vector components by the given scalar.

func (Vector3) Normalize

func (v Vector3) Normalize() Vector3

Normalize returns the unit vector in the same direction as v. Returns a zero vector if the magnitude is zero, near-zero, NaN, or Inf.

func (Vector3) Round

func (v Vector3) Round(precision int) Vector3

Round returns the vector with each component rounded to the given precision INFO: Rounding the vector components to the supplied precision.

func (Vector3) String

func (v Vector3) String() string

String returns a string representation of the vector INFO: Format the vector components to two decimal places for readability.

func (Vector3) Subtract

func (v Vector3) Subtract(other Vector3) Vector3

Subtract returns the difference of two vectors INFO: Subtracting other vector from this vector component-wise.

type Velocity

type Velocity struct {
	ecs.BasicEntity
	Vec Vector3
}

Velocity represents a 3D velocity

Jump to

Keyboard shortcuts

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