📄 ch03_trig_utilities.as
字号:
/*
. Ch. 3 - Trigonometry Utilities
Oct. 29, 2002
(c) 2002 Robert Penner
This is a collection of utility functions I use in my discussion
of trigonometry and coordinate systems.
Discussed in Chapter 3 of
Robert Penner's Programming Macromedia Flash MX
http://www.robertpenner.com/profmx
http://www.amazon.com/exec/obidos/ASIN/0072223561/robertpennerc-20
*/
Math.distance = function (x1, y1, x2, y2) {
var dx = x2 - x1;
var dy = y2 - y1;
return Math.sqrt (dx*dx + dy*dy);
};
Math.angleOfLine = function (x1, y1, x2, y2) {
return Math.atan2D (y2 - y1, x2 - x1);
};
Math.degreesToRadians = function (angle) {
return angle * (Math.PI / 180);
};
Math.radiansToDegrees = function (angle) {
return angle * (180 / Math.PI);
};
/*
// book version - less optimized
Math.fixAngle = function (angle) {
angle %= 360;
return (angle < 0) ? angle + 360 : angle;
};
*/
Math.fixAngle = function (angle) {
return (angle %= 360 < 0) ? angle + 360 : angle;
};
Math.cartesianToPolar = function (p) {
var radius = Math.sqrt (p.x*p.x + p.y*p.y);
var theta = Math.atan2D (p.y, p.x);
return {r:radius, t:theta};
};
Math.polarToCartesian = function (p) {
var x = p.r * Math.cosD (p.t);
var y = p.r * Math.sinD (p.t);
return {x:x, y:y};
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -