var Complex = function (x,y)
{
this.x=x;
this.y=y;
this.angle= function(){ return Math.atan(y/x);}
this.modes= function(){ return Math.sqrt(x*x+y*y); }
this.toString= function(){ return x+","+y;}
this.max= function() { return (x>y)?x:y;}
this.min= function() { return (x<y)?x:y;}
this.quad= function()
{
if(x>=0&&y>=0){ return 1;}
if(x>=0&&y<0){ return 4;}
if(x<0&&y>=0){ return 2;}
if(x<=0&&y<=0){ return 3;}
}
this.add= function(z) { return new Complex( this.x+z.x, this.y+z.y); } //加
this.sub= function(z) { return new Complex( this.x-z.x, this.y-z.y); } //减
this.flipy= function(){ return new Complex( this.x, -this.y); }
this.flipx= function(){ return new Complex( - this.x, this.y); }
this.inv= function() { return new Complex( - this.x, - this.y); }
this.multi= function(z) //乘
{
return new Complex( this.x*z.x- this.y*z.y, this.x*z.y+ this.y*z.x);
}
this.recip= function() //倒数
{
return new Complex( this.x/( this.x* this.x+ this.y* this.y), - this.y/( this.x* this.x+ this.y* this.y));
}
this.div = function(t) //除以实数
{
return new Complex( this.x/t, this.y/t);
}
this.divide= function(z) //除
{
return this.multi(z.recip());
}
this.rot = function(z0,t) //旋转指定角度
{
var Zangle= new Complex(Math.cos(t),Math.sin(t));
return this.sub(z0).multi(Zangle).add(z0);
}
}
{
this.x=x;
this.y=y;
this.angle= function(){ return Math.atan(y/x);}
this.modes= function(){ return Math.sqrt(x*x+y*y); }
this.toString= function(){ return x+","+y;}
this.max= function() { return (x>y)?x:y;}
this.min= function() { return (x<y)?x:y;}
this.quad= function()
{
if(x>=0&&y>=0){ return 1;}
if(x>=0&&y<0){ return 4;}
if(x<0&&y>=0){ return 2;}
if(x<=0&&y<=0){ return 3;}
}
this.add= function(z) { return new Complex( this.x+z.x, this.y+z.y); } //加
this.sub= function(z) { return new Complex( this.x-z.x, this.y-z.y); } //减
this.flipy= function(){ return new Complex( this.x, -this.y); }
this.flipx= function(){ return new Complex( - this.x, this.y); }
this.inv= function() { return new Complex( - this.x, - this.y); }
this.multi= function(z) //乘
{
return new Complex( this.x*z.x- this.y*z.y, this.x*z.y+ this.y*z.x);
}
this.recip= function() //倒数
{
return new Complex( this.x/( this.x* this.x+ this.y* this.y), - this.y/( this.x* this.x+ this.y* this.y));
}
this.div = function(t) //除以实数
{
return new Complex( this.x/t, this.y/t);
}
this.divide= function(z) //除
{
return this.multi(z.recip());
}
this.rot = function(z0,t) //旋转指定角度
{
var Zangle= new Complex(Math.cos(t),Math.sin(t));
return this.sub(z0).multi(Zangle).add(z0);
}
}
var z1= new Complex(1,2);
var z2= new Complex(3,4);
var z=z1.rot(z2,3.14);
var x=z.x;
var y=z.y;
alert(x+","+y)