getangleOrWay ( p1: Laya.Point, p2: Laya.Point )
{
// p1 开始坐标 p2结束坐标
/**与x轴顺时针的方向 */
/**方法1 */
let xx = p2.x - p1.x;
let yy = p2.y - p1.y;
// 斜边
let hypotenuse = Math.sqrt( Math.pow( xx, 2 ) + Math.pow( yy, 2 ) );
// yy >= 0 弧度在于 0 到 π 之间。(0~180°)
// yy < 0 弧度在于 π 到 2π 之间。(180°~360°)
let rad = yy >= 0 ? ( Math.acos( xx / hypotenuse ) ) : ( Math.PI * 2 - Math.acos( xx / hypotenuse ) );/**弧度 */
let angle = rad * 180 / Math.PI;/**角度 */
let dir = Math.floor( rad * 4 / Math.PI );/**八个方向 */
}
getangleOrWay2 ( p1: Laya.Point, p2: Laya.Point )
{
/**与x轴顺时针的方向 */
/**方法1 */
let xx = p2.x - p1.x;
let yy = p2.y - p1.y;
/**方法2 */
// yy >= 0 弧度在于 0 到 π 之间。(0~180°)
// yy < 0 弧度在于 π 到 2π 之间。(180°~360°)
let rad = yy >= 0 ? Math.atan2( yy, xx ) : ( Math.PI * 2 + Math.atan2( yy, xx ) );/**弧度 */
let angle = Math.floor( rad * 180 / Math.PI );/**角度 */
let dir = Math.floor( rad * 4 / Math.PI );/**八个方向 */
}
/**
* 八方向的
*/
public static getWay ( p1: Laya.Point, p2: Laya.Point ): number
{
/**与轴顺时针的方向 */
var a: number = Math.atan2( p1.y - p2.y, p1.x - p2.x );
var d: number = Math.floor( ( ( a + Math.PI * 3.625 ) % ( Math.PI * 2 ) ) / ( Math.PI / 4 ) );
return d;
}
/**
* 四方向的
*/
public static getWayInFour ( p1: Laya.Point, p2: Laya.Point )
{
/**与轴顺时针的方向 */
var a: number = Math.atan2( p2.y - p1.y, p2.x - p1.x );
var angle: number = a * 180 / Math.PI;
if ( angle < 0 )
{
angle = ( angle + 360 ) % 360;
}
if ( angle < 90 ) return 3;
else if ( angle >= 90 && angle < 180 ) return 5;
else if ( angle >= 180 && angle < 270 ) return 7;
else return 1;
}