Created
April 23, 2010 17:20
-
-
Save manveru/376834 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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