vector

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 2 Imported by: 1 module, 1 package

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vec

type Vec struct {
	X, Y float64
}

Vec is a two dimensional vector

func Add

func Add(v, u *Vec) *Vec

Add adds vector u to vector v and returns the vector

func Divide

func Divide(v *Vec, div float64) *Vec

Divide divides the vector by div and returns the vector

func Multiply

func Multiply(v *Vec, mul float64) *Vec

Multiply scales a vector by mul and returns the vector

func New

func New(x, y float64) *Vec

New returns a new vector at (x, y)

func Normalize

func Normalize(v *Vec) *Vec

Normalize normalizes the vector and returns the vector

func Project

func Project(v, u *Vec) *Vec

Project projects vector u onto vector v and returns the vector

func Rotate

func Rotate(v *Vec, angle float64) *Vec

Rotate rotates the vector by angle in radians and returns the vector

func Subtract

func Subtract(v, u *Vec) *Vec

Subtract subtracts vector u from vector v and returns the vector

func Unit

func Unit(angle float64) *Vec

Unit returns a unit vector at the given angle

func Zero

func Zero() *Vec

Zero returns a zero-vector

func (*Vec) Add

func (v *Vec) Add(u *Vec)

Add adds vector u to vector v

func (Vec) Angle

func (v Vec) Angle() float64

Angle returns the angle of a vector between [-PI, PI]

func (*Vec) Cap

func (v *Vec) Cap(max float64)

Cap limits the length of a vector. If it is longer than max, it will be cut down to length max

func (Vec) Cross

func (v Vec) Cross(u *Vec) float64

Cross calculates the cross product of two vectors and returns a scalar

func (*Vec) Divide

func (v *Vec) Divide(div float64)

Divide divides the vector by div

func (Vec) Dot

func (v Vec) Dot(u *Vec) float64

Dot calculates the dot product of two vectors and returns a scalar

func (*Vec) Magnitude

func (v *Vec) Magnitude() float64

Magnitude returns the magnitude of a vector

func (*Vec) Multiply

func (v *Vec) Multiply(mul float64)

Multiply scales a vector by mul

func (*Vec) Normalize

func (v *Vec) Normalize()

Normalize normalizes the vector

func (*Vec) Project

func (v *Vec) Project(u *Vec)

Project projects vector u onto vector v

func (*Vec) Rotate

func (v *Vec) Rotate(angle float64)

Rotate rotates the vector by angle in radians

func (*Vec) SetMagnitude

func (v *Vec) SetMagnitude(l float64)

SetMagnitude sets the magnitude of the vector to l

func (*Vec) String

func (v *Vec) String() string

String renders the vector as a string

func (*Vec) Subtract

func (v *Vec) Subtract(u *Vec)

Subtract subtracts vector u from vector v

Jump to

Keyboard shortcuts

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