home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
404 Jogos
/
CLJG.iso
/
Esportes
/
CrossingCup.swf
/
scripts
/
__Packages
/
sandy
/
math
/
VectorMath.as
< prev
next >
Wrap
Text File
|
2007-12-11
|
2KB
|
66 lines
class sandy.math.VectorMath
{
function VectorMath()
{
}
static function getNorm(v)
{
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
static function negate(v)
{
return new sandy.core.data.Vector(- v.x,- v.y,- v.z);
}
static function addVector(v, w)
{
return new sandy.core.data.Vector(v.x + w.x,v.y + w.y,v.z + w.z);
}
static function sub(v, w)
{
return new sandy.core.data.Vector(v.x - w.x,v.y - w.y,v.z - w.z);
}
static function pow(v, pow)
{
return new sandy.core.data.Vector(Math.pow(v.x,pow),Math.pow(v.x,pow),Math.pow(v.x,pow));
}
static function scale(v, n)
{
return new sandy.core.data.Vector(v.x * n,v.y * n,v.z * n);
}
static function dot(v, w)
{
return v.x * w.x + v.y * w.y + w.z * v.z;
}
static function cross(w, v)
{
return new sandy.core.data.Vector(w.y * v.z - w.z * v.y,w.z * v.x - w.x * v.z,w.x * v.y - w.y * v.x);
}
static function normalize(v)
{
var _loc1_ = sandy.math.VectorMath.getNorm(v);
if(_loc1_ == 0 || _loc1_ == 1)
{
return false;
}
v.x /= _loc1_;
v.y /= _loc1_;
v.z /= _loc1_;
return true;
}
static function getAngle(v, w)
{
var _loc1_ = sandy.math.VectorMath.dot(v,w) / (sandy.math.VectorMath.getNorm(v) * sandy.math.VectorMath.getNorm(w));
var _loc2_ = 1 - _loc1_ * _loc1_;
if(_loc2_ < 0)
{
trace(" wrong " + _loc1_);
_loc2_ = 0;
}
return Math.atan2(Math.sqrt(_loc2_),_loc1_);
}
static function clone(v)
{
return new sandy.core.data.Vector(v.x,v.y,v.z);
}
}