RSS | Twitter | Facebook
Home » ActionScript » 三角関数(回転行列を用いた円運動) : ActionScript

三角関数(回転行列を用いた円運動) : ActionScript

回転行列を用いた円運動のサンプルです。

/*回転行列を使った円運動*/
// クリップ作成オブジェクト
function PointClip(degree, radius, centerX, centerY) {
	// 変化分(弧度)
	var radian = Math.PI/180*degree;
	// 径
	var radius = radius;
	// 円中心
	var centerX = centerX;
	var centerY = centerY;
	// 三角比
	var cos = Math.cos(radian);
	var sin = Math.sin(radian);
	// 初期位置
	this._x = radius*Math.cos(0)+centerX;
	this._y = radius*Math.sin(0)+centerY;
	var i = 1;
	/* onEnterFrame */
	this.onEnterFrame = function() {
		var x1 = this._x-centerX;
		var y1 = this._y-centerY;
		var x2 = cos*x1-sin*y1;
		var y2 = sin*x1+cos*y1;
		this._x = x2+centerX;
		this._y = y2+centerY;
	};
}
// 角度の増分,半径,中心のX座標,Y座標
var o = new PointClip(5, 50, 100, 100);
_root.attachMovie('point', 'point', 0, o);

逆に回転させる

/*回転行列を使った円運動*/
// クリップ作成オブジェクト
function PointClip(degree, radius, centerX, centerY) {
	// 変化分(弧度)
	var radian = Math.PI/180*degree;
	// 径
	var radius = radius;
	// 円中心
	var centerX = centerX;
	var centerY = centerY;
	// 三角比
	var cos = Math.cos(radian);
	var sin = Math.sin(radian);
	// 初期位置
	this._x = radius*Math.cos(0)+centerX;
	this._y = radius*Math.sin(0)+centerY;
	var i = 1;
	/* onEnterFrame */
	this.onEnterFrame = function() {
		var x1 = this._x-centerX;
		var y1 = this._y-centerY;
		var x2 = cos*x1+sin*y1;
		var y2 = -sin*x1+cos*y1;
		this._x = x2+centerX;
		this._y = y2+centerY;
	};
}
// 角度の増分,半径,中心のX座標,Y座標
var o = new PointClip(5, 50, 100, 100);
_root.attachMovie('point', 'point', 0, o);

このページの上へ移動

  Yahoo!ブックマークに登録    Google  この記事をクリップ!  BuzzurlにブックマークBuzzurlにブックマーク

2008/5/8 木 | ActionScript, math, trigonometric | 固定リンク |

コメントはまだありません。

コメントの投稿

改行と段落タグは自動で挿入されます。メールアドレスは表示されません。
利用可能な HTML タグ :
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite="">
<cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(必須)

(必須)


トラックバックURL

このページの上へ移動