Documentation
¶
Overview ¶
v is a 2d vector package
Index ¶
- Variables
- type Vec
- func (v Vec) Abs() Vec
- func (v Vec) AbsX() float64
- func (v Vec) AbsY() float64
- func (v Vec) Add(a Vec) Vec
- func (v Vec) Angle() float64
- func (v Vec) AngleTo(other Vec) float64
- func (v Vec) Ceil() Vec
- func (v Vec) Cross(other Vec) float64
- func (v Vec) Dist(other Vec) float64
- func (v Vec) DistSq(other Vec) float64
- func (v Vec) Div(a Vec) Vec
- func (v Vec) DivS(s float64) Vec
- func (v Vec) Dot(other Vec) float64
- func (v Vec) Equals(other Vec) bool
- func (v Vec) EqualsPr(other Vec, allowedDelta float64) bool
- func (v Vec) Floor() Vec
- func (v Vec) IsZero() bool
- func (v Vec) Lerp(other Vec, t float64) Vec
- func (v Vec) Limit(max float64) Vec
- func (v Vec) Mag() float64
- func (v Vec) MagSq() float64
- func (v Vec) Mul(a Vec) Vec
- func (v Vec) Neg() Vec
- func (v Vec) NegX() Vec
- func (v Vec) NegY() Vec
- func (v Vec) Project(other Vec) Vec
- func (v Vec) Reflect(normal Vec) Vec
- func (v Vec) Rotate(angle float64) Vec
- func (v Vec) Round() Vec
- func (v Vec) Scale(s float64) Vec
- func (v Vec) Slerp(to Vec, weight float64) Vec
- func (v Vec) String() string
- func (v Vec) Sub(a Vec) Vec
- func (v Vec) Unit() Vec
Constants ¶
This section is empty.
Variables ¶
var ( // One Vec{1, 1} vector is a vector with all components set to 1. One = Vec{1, 1} // Left unit vector. Vec{-1, 0} Represents the direction of left. Left = Vec{-1, 0} // Right unit vector. Vec{1, 0} Represents the direction of right. Right = Vec{1, 0} // Up unit vector. Vec{0, -1} Y is down in 2D, so this vector points -Y. Up = Vec{0, -1} // Down unit vector. Vec{0, 1} Y is down in 2D, so this vector points +Y. Down = Vec{0, 1} )
Functions ¶
This section is empty.
Types ¶
type Vec ¶
type Vec struct {
X, Y float64
}
func (Vec) Cross ¶
Cross calculates the 2D vector cross product analog. The cross product of 2D vectors results in a 3D vector with only a z component. This function returns the magnitude of the z value.
func (Vec) DistSq ¶
DistSq returns the squared distance between this and other.
Faster than v.Dist() when you only need to compare distances.
func (Vec) Equals ¶
Equals checks if two vectors are equal. (Be careful when comparing floating point numbers!)
func (Vec) EqualsPr ¶
EqualsP returns they are practically equal with each other within a delta tolerance.
func (Vec) Floor ¶
Floor returns vector with all components rounded down (towards negative infinity).
func (Vec) MagSq ¶
MagSq returns the magnitude (length) of the vector, squared.
This method is often used to improve performance since, unlike Mag(), it does not require a Sqrt() operation.
func (Vec) Reflect ¶ added in v1.1.2
Reflect returns the reflection of the vector v over the given normal. normal should be a normalized (unit) vector.
func (Vec) Slerp ¶
Slerp performs spherical linear interpolation between two vectors with given weight value in [0,1] range, returning interpolated vector