3.三角学
360角度 == 6.2832弧度 ==2PI
180角度 == 3.1416弧度 ==PI
弧度(radians) = 角度(degrees) * Math.PI /180
角度(degrees) = 弧度(radians) * 180 / Math.PI
Flash使用弧度制所以sin、Cos里面参数为弧度、所以asin、acos出来的也是弧度要转换如:
trace(Math.sin(30 * Math.PI / 180));//0.5
trace(Math.asin(0.5) * 180 / Math.PI);//30
正弦(Sine)一个角的正弦值等于该角的对边与斜边的比
错误的写法trace(Math.sin(30));
记得将结果转换为弧度制trace(Math.sin(30 * Math.PI / 180));//0.5
记得y轴向上为负向下为正trace(Math.sin(-30 * Math.PI / 180));//-0.5向上
余弦值为邻边/斜边
trace(Math.cos(-30 * Math.PI / 180));
正切(Tangent)正切值为对边/邻边
trace(Math.tan(-30 * Math.PI / 180));
反正弦(Arcsine)和反余弦(Arccosine)反正切(Arctangent)
反正弦拿到正弦算角度----反余弦拿到余弦算角度----反正切拿到正切算角度
trace(Math.asin(0.5) * 180 / Math.PI);//30
trace(Math.acos(0.865) * 180 / Math.PI);
重要公式汇总
基本三角函数的计算:
角的正弦值 = 对边 / 斜边
角的余弦值 = 邻边 / 斜边
角的正切值 = 对边 / 邻边
角度制与弧度制的相互转换:
弧度 = 角度 * Math.PI / 180
角度 = 弧度 * 180 / Math.PI
向鼠标旋转(或向某点旋转):
// substitute mouseX, mouseY with the x, y point to rotate to
dx = mouseX - sprite.x;
dy = mouseY - sprite.y;
sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;
创建波形:
// assign value to x, y or other property of sprite or movie clip,
// use as drawing coordinates, etc.
public function onEnterFrame(event:Event){
value = center + Math.sin(angle) * range; angle += speed;
}
创建圆形:
// assign position to x and y of sprite or movie clip
// use as drawing coordinates, etc.
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radius;
yposition = centerY + Math.sin(angle) * radius;
angle += speed;
}
创建椭圆:
// assign position to x and y of sprite or movie clip,
// use as drawing coordinates, etc.
public function onEnterFrame(event:Event){
xposition = centerX + Math.cos(angle) * radiusX;
yposition = centerY + Math.sin(angle) * radiusY;
angle += speed;
}
计算两点间距离:
// points are x1, y1 and x2, y2
// can be sprite / movie clip positions, mouse coordinates, etc.
dx = x2 – x1;
dy = y2 – y1;
dist = Math.sqrt(dx*dx + dy*dy);
sin、cos速记
0-->90-->180-->270-->360
0-->1 -->0 -->-1 -->0
过控制点的曲线
// xt, yt is the point you want to draw through
// x0, y0 and x2, y2 are the end points of the curve
x1 = xt * 2 – (x0 + x2) / 2;
y1 = yt * 2 – (y0 + y2) / 2;
moveTo(x0, y0);
curveTo(x1, y1, x2, y2);
角速度
vx = Math.cos(angle) * speed;
vy = Math.sin(angle) * speed;
加速度
//ax,ay可以换成重力摩擦力弹力等用键盘控制其大小
vx += ax;
vy += ay;
调用 removeChild(对象名),删除影片或显示对象,会将对象实例从舞台上移除。请注意,被移除的显示对象仍然存在,只是看不到而已。如果要将该对象彻底删除,还应该调用 delete 对象名 将其完全删除