complex number
大学のJava演習をasで。
Javaの int hoge = 0; みたいな書き方が嫌いです。何となく。
乗算だけが課題なのでそれしか定義してません(◞‸◟)
♥0 |
Line 42 |
Modified 2010-04-21 12:01:58 |
MIT License
archived:2017-03-20 05:38:07
ActionScript3 source code
/**
* Copyright enecre ( http://wonderfl.net/user/enecre )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/rOeJ
*/
//大学のJava演習をasで。
//Javaの int hoge = 0; みたいな書き方が嫌いです。何となく。
//乗算だけが課題なのでそれしか定義してません(◞‸◟)
package {
import flash.display.Sprite;
import flash.text.TextField;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var rot30:Complex = new Complex(Math.sqrt(0.75),0.5);
var tf:TextField = new TextField();
tf.width = 500;
tf.text = rot30.toString();
var rot90:Complex = Complex.multiple(Complex.multiple(rot30,rot30),rot30);
tf.appendText("\n");
tf.appendText(rot90.toString());
addChild(tf);
}
}
}
class Complex{
private var _Re:Number;
private var _Im:Number;
public function Complex(_x:Number,_y:Number):void{
this._Re = _x;
this._Im = _y;
}
public static function multiple(a:Complex,b:Complex):Complex{
var len:Number = a.length() * b.length();
var rot:Number = a.rot() + b.rot();
var ret:Complex = new Complex(len*Math.cos(rot),len*Math.sin(rot));
return ret;
}
private function n2(n:Number):Number{
return Math.round(n*100)/100;
}
public function toString():String{
return String(n2(this._Re)) + " + " + String(n2(this._Im)) + "i";
}
public function length():Number{
return Math.sqrt(this._Re*this._Re+this._Im*this._Im);
}
public function rot():Number{
return Math.atan2(this._Im,this._Re);
}
}