Package physics provides vector types and operations to perform math and simple physics on those types. It also provides rules for attaching entities to vectors.




    View Source
    const (
    	// CUTOFF is used for rounding after floating point operations to
    	// zero out vector values that are sufficiently close to zero
    	CUTOFF = 0.001


    This section is empty.


    func Push

    func Push(a Pushes, b Pushable) error

      Push applies the force from the pushing object its target


      type Attachable

      type Attachable interface {
      	Detach() Vector
      	Attach(Attachable, ...float64) Vector
      	AttachX(Attachable, float64) Vector
      	AttachY(Attachable, float64) Vector
      	Vec() Vector

        Attachable represents things that can be attached to Vectors

        V2: x is 6.000000, y is 5.000000
        V3: x is 1.000000, y is 0.000000

        type ForceVector

        type ForceVector struct {
        	Force *float64

          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

                  func (*Mass) Freeze

                  func (m *Mass) Freeze()

                    Freeze changes a pushables mass such that it can no longer be pushed.

                    func (*Mass) GetMass

                    func (m *Mass) GetMass() float64

                      GetMass returns the mass of an object

                      func (*Mass) SetMass

                      func (m *Mass) SetMass(inMass float64) error

                        SetMass of an object

                        type Pushable

                        type Pushable interface {
                        	GetDelta() Vector
                        	GetMass() float64

                          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

                              func AngleVector(angle float64) Vector

                                AngleVector creates a unit vector by the cosine and sine of the given angle in degrees

                                func MaxVector

                                func MaxVector(a, b Vector) Vector

                                  MaxVector returns whichever vector has a greater magnitude

                                  func NewVector

                                  func NewVector(x, y float64) Vector

                                    NewVector returns a vector with the given x and y components

                                    func NewVector32

                                    func NewVector32(x, y float32) Vector

                                      NewVector32 accepts float32s (and will cast them to float64s), to create a vector

                                      func PtrVector

                                      func PtrVector(x, y *float64) Vector

                                        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) Add

                                        func (v Vector) Add(vs ...Vector) Vector

                                          Add combines a set of vectors through addition

                                          func (Vector) Angle

                                          func (v Vector) Angle() float64

                                            Angle returns this vector as an angle in degrees

                                            func (Vector) Attach

                                            func (v Vector) Attach(a Attachable, offsets ...float64) Vector

                                              Attach takes in something for this vector to attach to and a set of offsets. The resulting combined vector with the offsets is then returned, and needs to be assigned to the calling vector.

                                              func (Vector) AttachX

                                              func (v Vector) AttachX(a Attachable, offX float64) Vector

                                                AttachX performs an attachment that only attaches on the X axis.

                                                func (Vector) AttachY

                                                func (v Vector) AttachY(a Attachable, offY float64) Vector

                                                  AttachY performs an attachment that only attaches on the Y axis.

                                                  func (Vector) Copy

                                                  func (v Vector) Copy() Vector

                                                    Copy copies a Vector

                                                    func (Vector) Detach

                                                    func (v Vector) Detach() Vector

                                                      Detach returns a vector no longer attached to anything. The returned vector needs to be assigned to the caller for the caller to be replaced (vectors do not use pointer receivers)

                                                      func (Vector) Distance

                                                      func (v Vector) Distance(v2 Vector) float64

                                                        Distance on two vectors returns the euclidean distance from v to v2

                                                        func (Vector) Dot

                                                        func (v Vector) Dot(v2 Vector) float64

                                                          Dot returns the dot product of the vectors

                                                          func (Vector) GetForce

                                                          func (v Vector) GetForce() ForceVector

                                                            GetForce on a non-force vector returns a zero-value for force

                                                            func (Vector) GetPos

                                                            func (v Vector) GetPos() (float64, float64)

                                                              GetPos returns both v.X() and v.Y()

                                                              func (Vector) Magnitude

                                                              func (v Vector) Magnitude() float64

                                                                Magnitude returns the magnitude of the combined components of a Vector

                                                                func (Vector) Normalize

                                                                func (v Vector) Normalize() Vector

                                                                  Normalize divides both components in a vector by the vector's magnitude

                                                                  func (Vector) Rotate

                                                                  func (v Vector) Rotate(fs ...float64) Vector

                                                                    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

                                                                    func (v Vector) Scale(fs ...float64) Vector

                                                                      Scale scales a vector by a set of floating points Scale(f1,f2,f3) is equivalent to Scale(f1*f2*f3)

                                                                      func (Vector) SetPos

                                                                      func (v Vector) SetPos(x, y float64) Vector

                                                                        SetPos is equivalent to NewVector(x,y)

                                                                        func (Vector) SetX

                                                                        func (v Vector) SetX(x float64) Vector

                                                                          SetX returns a vector with its x component set to x

                                                                          func (Vector) SetY

                                                                          func (v Vector) SetY(y float64) Vector

                                                                            SetY returns a vector with its y component set to y

                                                                            func (Vector) ShiftX

                                                                            func (v Vector) ShiftX(x float64) Vector

                                                                              ShiftX is equivalent to v.X() += x

                                                                              func (Vector) ShiftY

                                                                              func (v Vector) ShiftY(y float64) Vector

                                                                                ShiftY is equivalent to v.Y() += y

                                                                                func (Vector) Sub

                                                                                func (v Vector) Sub(vs ...Vector) Vector

                                                                                  Sub combines a set of vectors through subtraction

                                                                                  func (Vector) Vec

                                                                                  func (v Vector) Vec() Vector

                                                                                    Vec returns a vector itself

                                                                                    func (Vector) X

                                                                                    func (v Vector) X() float64

                                                                                      X returns this vector's x component

                                                                                      func (Vector) Xp

                                                                                      func (v Vector) Xp() *float64

                                                                                        Xp returns the real pointer behind this vector's x component

                                                                                        func (Vector) Y

                                                                                        func (v Vector) Y() float64

                                                                                          Y returns this vector's x component

                                                                                          func (Vector) Yp

                                                                                          func (v Vector) Yp() *float64

                                                                                            Yp returns the real pointer behind this vector's y component

                                                                                            func (Vector) Zero

                                                                                            func (v Vector) Zero() Vector

                                                                                              Zero is shorthand for NewVector(0,0), but uses the input vector