Documentation ¶
Overview ¶
Package physics provides vector types and trivial physics manipulation for them.
Index ¶
- Constants
- func Push(a Pushes, b Pushable) error
- type Attachable
- type ForceVector
- type Mass
- type Pushable
- type Pushes
- type Vecer
- type Vector
- func (v Vector) Add(vs ...Vector) Vector
- func (v Vector) Angle() float64
- func (v *Vector) Attach(a Vecer, offX, offY float64)
- func (v *Vector) AttachX(a Vecer, offX float64)
- func (v *Vector) AttachY(a Vecer, offY float64)
- func (v Vector) Copy() Vector
- func (v *Vector) Detach()
- func (v *Vector) DetachX()
- func (v *Vector) DetachY()
- func (v Vector) Distance(v2 Vector) float64
- func (v Vector) Dot(v2 Vector) float64
- func (v Vector) GetForce() ForceVector
- func (v Vector) GetPos() (float64, float64)
- func (v Vector) Magnitude() float64
- func (v Vector) Normalize() Vector
- func (v Vector) Rotate(fs ...float64) Vector
- func (v Vector) Scale(fs ...float64) Vector
- func (v Vector) SetPos(x, y float64) Vector
- func (v Vector) SetX(x float64) Vector
- func (v Vector) SetY(y float64) Vector
- func (v Vector) ShiftX(x float64) Vector
- func (v Vector) ShiftY(y float64) Vector
- func (v Vector) Sub(vs ...Vector) Vector
- func (v Vector) Vec() Vector
- func (v Vector) X() float64
- func (v Vector) Xp() *float64
- func (v Vector) Y() float64
- func (v Vector) Yp() *float64
- func (v Vector) Zero() Vector
Examples ¶
Constants ¶
const ( // CUTOFF is used for rounding after floating point operations to // zero out vector values that are sufficiently close to zero CUTOFF = 0.001 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attachable ¶
type Attachable interface { Detach() Attach(Vecer, float64, float64) AttachX(Vecer, float64) AttachY(Vecer, float64) Vecer }
An Attachable can be attached to static or moving vectors.
Example ¶
v1 := NewVector(0, 0) v2 := NewVector(0, 0) v3 := NewVector(0, 0) v2.Attach(v1, 5, 5) v3.Attach(v1, 0, 0) v1.ShiftX(1) fmt.Printf("V2: x is %f, y is %f\n", v2.X(), v2.Y()) fmt.Printf("V3: x is %f, y is %f", v3.X(), v3.Y())
Output: V2: x is 6.000000, y is 5.000000 V3: x is 1.000000, y is 0.000000
type ForceVector ¶
ForceVector is a vector that has some force and can operate on entites with mass
func DefaultForceVector ¶
func DefaultForceVector(delta Vector, mass float64) ForceVector
DefaultForceVector returns a force vector that converts the mass given into a force float
func NewForceVector ¶
func NewForceVector(direction Vector, force float64) ForceVector
NewForceVector returns a force vector
func (ForceVector) GetForce ¶
func (f ForceVector) GetForce() ForceVector
GetForce is a self-returning call
type Mass ¶
type Mass struct {
// contains filtered or unexported fields
}
A Mass can have forces applied against it
type Pushable ¶
Pushable is implemented by anything that has mass and directional movement, and therefore can be pushed.
type Pushes ¶
type Pushes interface {
GetForce() ForceVector
}
A Pushes can push Pushable things through its associated ForceVector, or how hard the Pushable should move in a given direction
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
A Vector is a two-dimensional point or vector used throughout oak to maintain functionality between packages.
func AngleVector ¶
AngleVector creates a unit vector by the cosine and sine of the given angle in degrees
func NewVector32 ¶
NewVector32 accepts float32s (and will cast them to float64s), to create a vector
func PtrVector ¶
PtrVector takes in pointers as opposed to float values-- these same pointers will be used in the returned vector and by attachments to that vector.
func (*Vector) Attach ¶
Attach takes in something for this vector to attach to and a set of offsets.
func (*Vector) Detach ¶
func (v *Vector) Detach()
Detach modifies a vector to no longer be attached to anything.
func (*Vector) DetachX ¶
func (v *Vector) DetachX()
DetachX modifies a vector to no longer be attached on the X Axis.
func (*Vector) DetachY ¶
func (v *Vector) DetachY()
DetachY modifies a vector to no longer be attached on the Y Axis.
func (Vector) GetForce ¶
func (v Vector) GetForce() ForceVector
GetForce on a non-force vector returns a zero-value for force
func (Vector) Rotate ¶
Rotate takes in a set of angles and rotates v by their sum the input angles are assumed to be in degrees.
func (Vector) Scale ¶
Scale scales a vector by a set of floating points Scale(f1,f2,f3) is equivalent to Scale(f1*f2*f3)