Last active
June 17, 2016 03:03
-
-
Save ten-A/4bf20c54e6c52ffc4230d2a40ab8c9a5 to your computer and use it in GitHub Desktop.
Complex Field Computing Library for Extendscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// complex numbers Constructer | |
function C(r,i){ | |
this.r = r; //real | |
this.i = i; //imaginary | |
} | |
//compute complex value | |
function Cconj(c){ //conjunction | |
return new C(c.r, -c.i); | |
} | |
function Cadd(c,d){ //add | |
return new C(c.r+d.r, c.i+d.i); | |
} | |
function Csub(c,d){ //sub | |
return new C(c.r-d.r, c.i-d.i); | |
} | |
function Cmul(c,d){ //multi | |
return new C(c.r*d.r-c.i*d.i, c.r*d.i+c.i*d.r); | |
} | |
function Cdiv(c,d){ //division | |
return new C( | |
(c.r*d.r+c.i*d.i)/(d.r*d.r+d.i*d.i), | |
(c.r*d.i-c.i*d.r)/(d.r*d.r+d.i*d.i) | |
); | |
} | |
function Csqrt(c){ //square root | |
return new C( | |
Math.sqrt(Math.sqrt(c.r*c.r+c.i*c.i))*Math.cos(Math.atan2(c.i,c.r)/2), | |
Math.sqrt(Math.sqrt(c.r*c.r+c.i*c.i))*Math.sin(Math.atan2(c.i,c.r)/2) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment