flash三角学
radians = degrees * Math.PI / 180
degrees = radians * 180 / Math.PI
在FLASH中,
坐标系是左上角(0, 0),(→x正,↓y正)。
顺时针为正角度。
用弧度表示角,而不是角度。
正弦函数 Math.sin(angle)
余弦函数 Math.cos(angle)
正切函数 Math.tan(angle)
反正弦 Math.asin(ratio)
反余弦 Math.acos(ratio)
反正切 Math.atan(ratio)
另一个反正切 Math.atan2(y.x)
dx = x2 - x1;
dy = y2 - y1;
dist = Math.sqrt(dx*dx + dy*dy);
旋转到鼠标位置(或任意点):
// 用x,y点替换mouseX,mouseY来旋转
dx = mouseX - sprite.x;
dy = mouseY - sprite.y;
sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;
创建波:
// 指定值给精灵或影片剪辑的x,y或其它属性,
// 用于绘制坐标等。
public function onEnterFrame(event:Event) {
value = center + Math.sin(angle) * range;
angle += speed;
}
创建圆:
public function onEnterFrame(event:Event) {
xposition = centerX + Math.cos(angle) * radius;
yposition = centerY + Math.sin(angle) * radius;
angle += speed;
}
创建椭圆:
public function onEnterFrame(event:Event) {
xposition = centerX + Math.cos(angle) * radiusX;
yposition = centerY + Math.sin(angle) * radiusY;
angle += speed;
}
上一篇:flash杂项
下一篇:无