Skip to content

Instantly share code, notes, and snippets.

@manveru
Created April 23, 2010 17:20
Show Gist options
  • Save manveru/376834 to your computer and use it in GitHub Desktop.
Save manveru/376834 to your computer and use it in GitHub Desktop.
type Vector struct {
y, x float64
}
func (self *Vector) Normalize() {
length := self.Length()
self.y /= length
self.x /= length
}
func (self *Vector) Length() float64 {
return math.Sqrt((self.x * self.x) + (self.y * self.y))
}
func (self *Vector) Minus(other Vector) (result Vector) {
return Vector{x: (self.x - other.x), y: (self.y - other.y)}
}
func (self *Vector) MultiplyNum(other float64) (result Vector) {
return Vector{x: (self.x * other), y: (self.y * other)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment