vector

package
Version: v0.0.0-...-1b60a0e Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package vector represents a vector in a left-handed 3D coordinate system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DotProduct

func DotProduct(vec1, vec2 Vector) float64

DotProduct computes and returns the dot product of passed Vectors.

Types

type Vector

type Vector struct {
	// X, Y, and Z represent components in a left-handed 3D coordinate system
	X, Y, Z float64
}

Vector represents a vector in a left-handed 3D coordinate system

func Add

func Add(vec1, vec2 Vector) Vector

Add returns a new Vector with components equal to the sum of the corresponding components in the passed Vectors.

func CrossProduct

func CrossProduct(vec1, vec2 Vector) Vector

CrossProduct computes and returns a new Vector that is the cross product of the passed Vectors.

func NewVector

func NewVector(x, y, z float64) *Vector

NewVector returns a new Vector that has the passed X, Y, and Z values.

func Normalize

func Normalize(vec Vector) *Vector

Normalize returns a new Vector that is the result of normalizing the passed Vector.

func Reflect

func Reflect(in, normal Vector) *Vector

Reflect returns a new Vector that is the results of reflecting the passed in Vector around the passed normal Vector.

func Scale

func Scale(vec Vector, scalar float64) *Vector

Scale returns a new Vector that is the result of scaling the passed Vector by the passed scalar value.

func Subtract

func Subtract(vec1, vec2 Vector) *Vector

Subtract returns a new Vector with components equal to the difference of the corresponding components in the passed Vectors.

func (*Vector) Add

func (vec *Vector) Add(vec2 Vector) *Vector

Add modifies each component of this Vector by setting each of them to the sum of the components in this Vector and the passed Vector.

func (*Vector) Equals

func (vec *Vector) Equals(vecQ *Vector) bool

Equals returns true if the passed Vector is equal to this Vector. Two Vectors are equal if their X, Y, Z components are equal.

func (*Vector) Magnitude

func (vec *Vector) Magnitude() float64

Magnitude computes and returns the length of this Vector. The length is calculated using Pythagoras' theorem.

func (*Vector) Negate

func (vec *Vector) Negate() *Vector

Negate multiplies each of this Vector's components by -1.

func (*Vector) Normalize

func (vec *Vector) Normalize() *Vector

Normalize normalizes this Vector by converting it to a unit vector.

func (*Vector) Scale

func (vec *Vector) Scale(scalar float64) *Vector

Scale multiplies each of this Vector's components by the passed scalar value.

func (*Vector) Subtract

func (vec *Vector) Subtract(vec2 Vector) *Vector

Subtract modifies each component of this Vector by setting each of them to the difference of the components in this Vector and the passed Vector.

Source Files

Jump to

Keyboard shortcuts

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