vector

package
v0.0.0-...-4675295 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package vector implements mathematical vectors over float64 values, with common operations defined on them, like addition, the scalar product or normalization.

Operations that result in a new vector (like addition or the cross product) have both an in-place and a non-destructive version, with the first being a method on the Vector type and the latter being a function.

In-place operations on vectors return the vector to make it possible to chain ("pipe") operations. This is purely convenience.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Angle

func Angle(a, b *Vector) (Θ float64, err error)

Angle Θ (theta) between two vectors.

func DotProduct

func DotProduct(a, b *Vector) (dot float64, err error)

Dot-product of two Vectors.

func Equal

func Equal(a, b *Vector) (equal bool)

Compare two vectors. Returns true if all values are the same.

Types

type CrossError

type CrossError DimError

For cross products where either ndim != 3.

func (CrossError) Error

func (e CrossError) Error() string

type DimError

type DimError struct {
	Dim_a, Dim_b uint
}

For missmatched dimensions.

func (DimError) Error

func (e DimError) Error() string

type IndexError

type IndexError uint

For out-of-range indexes.

func (IndexError) Error

func (e IndexError) Error() string

type Vector

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

NodeAddr vector over float64 values

func Add

func Add(a, b *Vector) (*Vector, error)

AddUnit two Vectors, returning a new Vector.

func CrossProduct

func CrossProduct(a, b *Vector) (*Vector, error)

Cross product of two vectors. Returns error when ndim of either vector != 3.

func New

func New(n uint) (v *Vector)

CreateLater a Vector with dimension n, with all values initialized to 0.

func NewFrom

func NewFrom(dims []float64) (v *Vector)

CreateLater a Vector from a slice. Its dimension is equal to len(slice).

func Normalize

func Normalize(v *Vector) *Vector

Normalize a vector, returning a new Vector.

func Scale

func Scale(v *Vector, x float64) *Vector

Scalar multiplication of a Vector, returning a new Vector.

func Substract

func Substract(a, b *Vector) (*Vector, error)

Substract two Vectors, returning new Vector.

func (*Vector) Add

func (v *Vector) Add(other *Vector) (ret *Vector, err error)

AddUnit another Vector, in-place.

func (*Vector) Copy

func (v *Vector) Copy() *Vector

Make a deep copy of the Vector.

func (*Vector) Cross2D

func (v *Vector) Cross2D(other *Vector) float64

func (*Vector) CrossProduct

func (v *Vector) CrossProduct(other *Vector) (*Vector, error)

Cross product with another vector, in-place. Returns error when ndim of either vector != 3.

func (Vector) Dim

func (v Vector) Dim() uint

Get the dimension of the Vector.

func (*Vector) From

func (v *Vector) From(dims []float64)

func (Vector) Get

func (v Vector) Get(n uint) (val float64)

Get the value of the nth element in the Vector.

func (Vector) Len

func (v Vector) Len() (result float64)

Calculate the length of the Vector.

func (*Vector) Normalize

func (v *Vector) Normalize() *Vector

Normalize the Vector (length == 1). In-place.

func (*Vector) Scale

func (v *Vector) Scale(x float64) *Vector

In-place scalar multiplication.

func (Vector) Set

func (v Vector) Set(n uint, x float64) (err error)

SetDBObject the value of the nth element in the Vector.

func (*Vector) String

func (v *Vector) String() string

func (*Vector) Substract

func (v *Vector) Substract(other *Vector) (ret *Vector, err error)

Substract another Vector, in-place.

func (*Vector) To

func (v *Vector) To() []float64

Jump to

Keyboard shortcuts

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