home *** CD-ROM | disk | FTP | other *** search
- class CVector2D
- {
- var x;
- var y;
- function CVector2D(x_, y_)
- {
- this.x = x_;
- this.y = y_;
- }
- function reinit(x_, y_)
- {
- this.x = x_;
- this.y = y_;
- }
- function getUgol()
- {
- return Math.atan2(this.y,this.x);
- }
- function duplicate()
- {
- return new CVector2D(this.x,this.y);
- }
- function copyTo(v)
- {
- v.x = this.x;
- v.y = this.y;
- }
- function minus(v)
- {
- this.x -= v.x;
- this.y -= v.y;
- }
- function minusNew(v)
- {
- return new CVector2D(this.x - v.x,this.y - v.y);
- }
- function normalize()
- {
- var _loc2_ = Math.sqrt(this.x * this.x + this.y * this.y);
- if(_loc2_ > 0.001)
- {
- this.x /= _loc2_;
- this.y /= _loc2_;
- }
- }
- function reverseNew()
- {
- return new CVector2D(- this.x,- this.y);
- }
- function scalar(v)
- {
- return this.x * v.x + this.y * v.y;
- }
- function modul()
- {
- return Math.sqrt(this.x * this.x + this.y * this.y);
- }
- function reflectFromNormal(n)
- {
- var _loc2_ = Math.atan2(n.y,n.x);
- this.rotate(- _loc2_);
- this.x = - this.x;
- this.rotate(_loc2_);
- }
- function rotate(u)
- {
- var _loc4_ = this.x;
- var _loc3_ = this.y;
- this.x = _loc4_ * Math.cos(u) - _loc3_ * Math.sin(u);
- this.y = _loc4_ * Math.sin(u) + _loc3_ * Math.cos(u);
- }
- function rotateNew(u)
- {
- return new CVector2D(this.x * Math.cos(u) - this.y * Math.sin(u),this.x * Math.sin(u) + this.y * Math.cos(u));
- }
- function mult(k)
- {
- this.x *= k;
- this.y *= k;
- }
- function multNew(k)
- {
- return new CVector2D(this.x * k,this.y * k);
- }
- function plus(v)
- {
- this.x += v.x;
- this.y += v.y;
- }
- function plusNew(v)
- {
- return new CVector2D(this.x + v.x,this.y + v.y);
- }
- function getDistanceTo(p1, p2)
- {
- var _loc3_ = p1.y - p2.y;
- var _loc2_ = p2.x - p1.x;
- var _loc6_ = p1.x * (p2.y - p1.y) - p1.y * (p2.x - p1.x);
- var _loc5_ = Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
- _loc3_ /= _loc5_;
- _loc2_ /= _loc5_;
- _loc6_ /= _loc5_;
- return _loc3_ * this.x + _loc2_ * this.y + _loc6_;
- }
- }
-