Possible fix for #391

This commit is contained in:
Shoghi Cervantes 2013-06-15 21:24:06 +02:00
parent 204a4ce831
commit 02721c09a4
5 changed files with 89 additions and 9 deletions

View file

@ -110,6 +110,26 @@ class Vector2{
return pow($this->x - $x, 2) + pow($this->y - $y, 2);
}
}
public function length(){
return sqrt($this->lengthSquared());
}
public function lengthSquared(){
return $this->x * $this->x + $this->y * $this->y;
}
public function normalize(){
$len = $this->length();
if($len != 0){
return $this->divide($len);
}
return new Vector2(0, 0);
}
public function dot(Vector2 $v){
return $this->x * $v->x + $this->y * $v->y;
}
public function __toString(){
return "Vector2(x=".$this->x.",y=".$this->y.")";