home *** CD-ROM | disk | FTP | other *** search
- class math.Vector extends flash.geom.Point
- {
- function Vector(x1, y1)
- {
- super();
- this.x = x1;
- this.y = y1;
- if(isNaN(this.x))
- {
- this.x = 0;
- }
- if(isNaN(this.y))
- {
- this.y = 0;
- }
- }
- function sum()
- {
- return this.x + this.y;
- }
- function setTo(px, py)
- {
- this.x = px;
- this.y = py;
- }
- function copy(v)
- {
- this.x = v.x;
- this.y = v.y;
- }
- function dot(v)
- {
- return this.x * v.x + this.y * v.y;
- }
- function cross(v)
- {
- return this.x * v.y - this.y * v.x;
- }
- function plus(v)
- {
- this.x += v.x;
- this.y += v.y;
- }
- function minus(v)
- {
- this.x -= v.x;
- this.y -= v.y;
- }
- function mult(s)
- {
- this.x *= s;
- this.y *= s;
- }
- function plusNew(v)
- {
- return new math.Vector(this.x + v.x,this.y + v.y);
- }
- function minusNew(v)
- {
- return new math.Vector(this.x - v.x,this.y - v.y);
- }
- function multNew(s)
- {
- return new math.Vector(this.x * s,this.y * s);
- }
- static function equal(v1, v2)
- {
- return v1.x == v2.x && v1.y == v2.y;
- }
- function clone()
- {
- return new math.Vector(this.x,this.y);
- }
- function add(p)
- {
- return new math.Vector(this.x + p.x,this.y + p.y);
- }
- function subtract(p)
- {
- return new math.Vector(this.x - p.x,this.y - p.y);
- }
- function get len_2()
- {
- return this.x * this.x + this.y * this.y;
- }
- function simple(u)
- {
- this.x = Math.round(this.x / u) * u;
- this.y = Math.round(this.y / u) * u;
- }
- function rotate(a)
- {
- var _loc2_ = Math.cos(a);
- var _loc3_ = Math.sin(a);
- var _loc5_ = this.x;
- var _loc4_ = this.y;
- this.x = _loc5_ * _loc2_ - _loc4_ * _loc3_;
- this.y = _loc5_ * _loc3_ + _loc4_ * _loc2_;
- }
- function transform(m)
- {
- var _loc4_ = this.x;
- var _loc3_ = this.y;
- this.x = _loc4_ * m.a + _loc3_ * m.c + m.tx;
- this.y = _loc4_ * m.b + _loc3_ * m.d + m.ty;
- }
- function isRight(p)
- {
- return math.Vector.crossProduct(this,p) < 0;
- }
- function isInside(pArr)
- {
- var _loc4_ = pArr.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- var _loc3_ = pArr[_loc2_];
- if(!this.subtract(_loc3_).isRight(pArr[_loc2_ != _loc4_ - 1 ? _loc2_ + 1 : 0].subtract(_loc3_)))
- {
- return false;
- }
- _loc2_ = _loc2_ + 1;
- }
- return true;
- }
- function getMp()
- {
- var _loc2_ = new math.Vector(this.y,- this.x);
- _loc2_.normalize(1);
- return _loc2_;
- }
- static function polar(len, angle)
- {
- var _loc1_ = flash.geom.Point.polar(len,angle);
- return new math.Vector(_loc1_.x,_loc1_.y);
- }
- static function interpolate(pt1, pt2, f)
- {
- var _loc1_ = flash.geom.Point.interpolate(pt1,pt2,f);
- return new math.Vector(_loc1_.x,_loc1_.y);
- }
- static function getK(p, m, n)
- {
- return math.Vector.crossProduct(p,n) / math.Vector.crossProduct(m,n);
- }
- static function getHorizontal(p, p0)
- {
- var _loc1_ = math.Vector.dotProduct(p,p0) / p0.len_2;
- return new math.Vector(p0.x * _loc1_,p0.y * _loc1_);
- }
- static function getVertical(p, p0)
- {
- var _loc2_ = p0.len_2;
- return new math.Vector(p0.y * math.Vector.crossProduct(p,p0) / _loc2_,p0.x * math.Vector.crossProduct(p0,p) / _loc2_);
- }
- static function dotProduct(p1, p2)
- {
- return p1.x * p2.x + p1.y * p2.y;
- }
- static function crossProduct(p1, p2)
- {
- return p1.x * p2.y - p2.x * p1.y;
- }
- static function intersects(p1, p2, p3, p4)
- {
- var _loc6_ = p3.subtract(p1);
- var _loc5_ = p2.subtract(p3);
- var _loc8_ = math.Vector.crossProduct(_loc6_,_loc5_);
- var _loc3_ = p4.subtract(p2);
- var _loc4_ = math.Vector.crossProduct(_loc5_,_loc3_);
- if(_loc8_ * _loc4_ < 0)
- {
- return false;
- }
- var _loc1_ = p1.subtract(p4);
- var _loc2_ = math.Vector.crossProduct(_loc3_,_loc1_);
- if(_loc4_ * _loc2_ < 0)
- {
- return false;
- }
- var _loc7_ = math.Vector.crossProduct(_loc1_,_loc6_);
- if(_loc2_ * _loc7_ < 0)
- {
- return false;
- }
- return true;
- }
- static function intersection(p1, p2, p3, p4)
- {
- var _loc2_ = math.Vector.crossProduct(p1,p3);
- var _loc5_ = math.Vector.crossProduct(p2,p4);
- var _loc7_ = math.Vector.crossProduct(p3,p2);
- var _loc1_ = math.Vector.crossProduct(p4,p1);
- var _loc3_ = math.Vector.crossProduct(p3,p4);
- var _loc10_ = (_loc2_ + _loc3_ + _loc1_) / (_loc2_ + _loc5_ + _loc7_ + _loc1_);
- return math.Vector.interpolate(p2,p1,_loc10_);
- }
- }
-