geometry

package
v0.0.0-...-59476ba Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2018 License: MIT Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AngleFromOrigin

func AngleFromOrigin(v Vector) (float64, error)

AngleFromOrigin calculates the angle of a given vector from the origin relative to the x-axis of 𝐄 (the model environment)

func AngleToIntercept

func AngleToIntercept(pos Vector, dir𝚹 float64, target Vector) (float64, error)

AngleToIntercept calculates the change in angle required from the current heading to point in direction of target.

func DotProduct

func DotProduct(v Vector, u Vector) (float64, error)

DotProduct returns the sum of the product of elements of two i-dimension vectors, u and v, as a scalar s.t. v•v = (v₁u₁ + v₂u₂ + ⠂⠂⠂ + vᵢ₋₁uᵢ₋₁ + vᵢuᵢ)

func Magnitude

func Magnitude(v Vector) (float64, error)

Magnitude does the classic calculation for length of a vector (or, distance from origin)

func RelativeAngle

func RelativeAngle(v Vector, u Vector) (float64, error)

RelativeAngle – does what it says on the box. Only implemented in 2D currently, or, as a comparitive rotation between two points on a single plane.

func TranslatePositionToSector2D

func TranslatePositionToSector2D(ed float64, n int, v Vector) (int, int)

TranslatePositionToSector2D : translates the co-ordinates of a 2D vector to sector indices location (2D Version)

func UnitAngle

func UnitAngle(angle float64) float64

UnitAngle will map any floating-point value to its angle on a unit circle.

func VectorDistance

func VectorDistance(v Vector, u Vector) (float64, error)

VectorDistance calculates the distance between two positions

Types

type Vector

type Vector []float64

Vector : Any sized dimension representation of a point of vector space.

func CrossProduct

func CrossProduct(v Vector, u Vector) (Vector, error)

CrossProduct produces a new Vector orthogonal to both v and u. Only supported for 3D vectors.

func FuzzifyVector

func FuzzifyVector(v Vector, ε float64) (Vector, error)

FuzzifyVector will return a a 'fuzzy', slightly randomised version of v, at a random variance in range (-ε, +ε) offset from each existing element of v.

func Normalise

func Normalise(v Vector) (Vector, error)

Normalise returns the normalised Vector of v – it's what you might call a direction vector, as opposed to a position vector. NOTE: this is not the same as a 'norm'/'normal' which is the vector orthogonal to a plane or surface.

func RandVector

func RandVector(bounds []float64) Vector

RandVector will give a random vector within boundaries the axes of len(bounds) dimensions

func UnitVector

func UnitVector(angle float64) Vector

UnitVector returns a direction unit vector for an axis pair.

func VecAddition

func VecAddition(v Vector, u Vector) (Vector, error)

VecAddition – performs vector addition between two vectors, v and u s.t. v + u = [v₁+u₁ , v₂+u₂, ⠂⠂⠂ , vᵢ₋₁+uᵢ₋₁ , vᵢ+uᵢ ] on an i-th dimension vector.

func VecScalarMultiply

func VecScalarMultiply(v Vector, scalar float64) (Vector, error)

VecScalarMultiply - performs scalar multiplication on a vector v, s.t. scalar * v = [scalar*e1, scalar*e2, scalar*e3]

func (Vector) Equal

func (v Vector) Equal(u VectorEquality) bool

Equal method implements an Equality comparison between vectors.

type VectorEquality

type VectorEquality interface {
	Equal(VectorEquality) bool
}

VectorEquality – Trying to implement a quick version of checking for Vector equality

Jump to

Keyboard shortcuts

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