Documentation ¶
Index ¶
- Variables
- type Rectangle
- type Vector
- func (v *Vector) Add(nv *Vector) *Vector
- func (v *Vector) Angle() float64
- func (v *Vector) Copy() *Vector
- func (v *Vector) Cross(nv *Vector) float64
- func (v *Vector) Dot(nv *Vector) float64
- func (v *Vector) Equal(nv *Vector) bool
- func (v *Vector) Len() float64
- func (v *Vector) Lerp(a *Vector, b *Vector, t float64) *Vector
- func (v *Vector) Map(f func(float64) float64) *Vector
- func (v *Vector) Normal() *Vector
- func (v *Vector) Project(nv *Vector) *Vector
- func (v *Vector) Rotated(angle float64) *Vector
- func (v *Vector) Scaled(s float64) *Vector
- func (v *Vector) ScaledXY(nv *Vector) *Vector
- func (v *Vector) String() string
- func (v *Vector) Sub(nv *Vector) *Vector
- func (v *Vector) Unit() *Vector
- func (v *Vector) XY() (x, y float64)
Constants ¶
This section is empty.
Variables ¶
var ZV = &Vector{0, 0}
ZV is a zero vector
Functions ¶
This section is empty.
Types ¶
type Rectangle ¶
type Rectangle struct {
Min, Max Vector
}
Rectangle is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.
The invariant should hold, that Max's components are greater or equal than Min's components respectively.
func RectImageCopy ¶
RectImageCopy converts an image rectangle to model rect
type Vector ¶
type Vector struct {
X, Y float64
}
Vector is a 2D vector type with X and Y coordinates
func NewVectorFromPoint ¶
NewVectorFromPoint converts an image point to a vector
func (*Vector) Angle ¶
Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].
func (*Vector) Lerp ¶
Lerp returns a linear interpolation between vector a and b.
This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.
func (*Vector) Map ¶
Map applies the function f to both x and y components of the vector u and returns the modified vector.
u := pixel.V(10.5, -1.5) v := nv.Map(math.Floor) // v is Vector(10, -2), both components of u floored
func (*Vector) Normal ¶
Normal returns a vector normal to nv. Equivalent to nv.Rotated(math.Pi / 2), but faster.
func (*Vector) Project ¶
Project returns a projection (or component) of vector u in the direction of vector v.
Behaviour is undefined if v is a zero vector.