flash相册代码: -
import flash.geom.Point; -
//---const -
var RTOA:Number = 180/Math.PI; -
var ATOR:Number = Math.PI/180; -
var P360:Number = Math.PI*2; -
//base function -
//获得两个Point之间的夹角 -
function getAngle(point_a:Point, point_b:Point):Number { -
return Math.atan2(point_b.y-point_a.y, point_b.x-point_a.x); -
} -
//获取由三个点构成的两条线ab bc之间的夹角 -
function getPointAngle(point_a:Point, point_b:Point, point_c:Point):Number { -
var angle:Number = getAngle(point_b, point_a)-getAngle(point_b, point_c); -
if (angle>Math.PI*2) { -
angle -= Math.PI*2; -
} else if (angle>=Math.PI) { -
angle -= Math.PI; -
} else if (angle<=-Math.PI) { -
angle += Math.PI*2; -
} else if (angle<0) { -
angle += Math.PI; -
} -
return angle; -
} -
//判断一条直线上,a点是否位于b、c点之间,如果位于,返回比较靠近的点,否则返回undefined -
function aInBC(a:Point, b:Point, c:Point):Boolean { -
return Point.distance(a, b)+Point.distance(a, c)<=Point.distance(b, c)+1 -
} -
//得到斜率 -
function getK(point_1:Point, point_2:Point):Number { -
var k:Number; -
if (point_2.y == point_1.y) { -
k = 0.000001; -
} else if (point_2.x == point_1.x) { -
k = 1000000 -
} else { -
k = (point_2.y-point_1.y)/(point_2.x-point_1.x); -
} -
return k; -
} -
//point_a到由point_1和point_2构成的直线的垂直交点(法线点) -
function pointToLine(point_1:Point, point_2:Point, point_a:Point):Point { -
//斜率K -
var k1:Number; -
var k2:Number; -
//偏移量a -
var a1:Number; -
var a2:Number; -
var point_b:Point = new Point(); -
k1 = getK(point_1, point_2); -
k2 = -1/k1; -
a1 = point_1.y-k1*point_1.x; -
a2 = point_a.y-k2*point_a.x; -
point_b = new Point(); -
point_b.x = (a2-a1)/(k1-k2); -
point_b.y = k1*point_b.x+a1; -
return point_b; -
} -
//point_a到由point_1和point_2构成的直线的距离 -
function distancePointToLine(point_1:Point, point_2:Point, point_a:Point):Number { -
var point_b:Point = new Point(); -
point_b = PointToLine(point_1, point_2, point_a); -
return Point.distance(point_a, point_b); -
} -
//两条直线的交点 -
function crossPoint(p1:Point,k1:Number ,p2:Point ,k2:Number):Point{ -
var c:Point=new Point() -
if(k1==k2){ -
return undefined -
}else{ -
c.x=(p1.y-k1*p1.x-p2.y+k2*p2.x)/(k1-k2) -
c.y=(k1*c.x+p1.y-k1*p1.x) -
} -
|