web,direction,planning,graphicdesign

2009年10月12日月曜日

ActionScript 三角関数の基本的な公式

■基本的な三角関数の計算

角度のサイン = 対辺/斜辺
角度のコサイン = 隣辺/斜辺
角度のタンジェント = 対辺/隣辺


■ラジアンから度へ、度からラジアンへの変換

ラジアン = 度 * Math.PI / 180
度 = ラジアン * 180 / Math.PI


■マウスの方向への回転
// mouseXやmouseYは任意の点のx,yに置き換える
dx = mouseX - sprite.x;
dy = mouseY - sprite.y;
sprite.rotation = Math.atan2(dy.dx)* 180 / Math.PI;


■波の作成
//valueはスプライトやムービークリップのx,yにその他のプロパティに割当
public function onEnterFrame(event:Event){
value = center + Math.sin(angle) * range;
angle += speed;
}


■円の作成
//Xposition,Ypositionをスプライトやムービークリップのxとyに割りあて
public function onEnterFrame(event:Event){
Xposition = centerX + Math.cos(angle)*radius;
Yposition = centerY + Math.sin(angle)*radius;
angle += speed;
}

■2点間の距離の取得
dx = x2 - x1;
dy = y2 - y1;
dist = Math.sqrt(dx*dx + dy*dy);

フォロワー