使用Flex开发Activiti流程设计器(七)-线条箭头画法

画线条的箭头要根据线条的开始坐标和结束坐标来确定角度

 

代码:

 

public function drawArrow(ui:Sprite,fromPoint:Point,toPoint:Point,color:uint):void  
		{  
			ui.graphics.lineTo(toPoint.x,toPoint.y);
			var vDistance:Number= toPoint.y-fromPoint.y;//起始点垂直距离  
			var sDistance:Number=Point.distance(fromPoint,toPoint);//起始点直线距离  
			var sinValue:Number=vDistance/sDistance;//起始点间的夹角的sin值  
			/**两点间直线与水平线的角度(弧度)*/  
			var radian:Number=Math.asin(sinValue); 
			this.radian = radian;
			/**用于计算三角形顶点与目标点水平距离的夹角(弧度)*/  
			var hRadian:Number=Math.PI/6-radian;  
			/**用于计算三角形顶点与目标点垂直距离的夹角(弧度)*/  
			var vRadian:Number=radian+Math.PI/6;  
			/**上顶点与目标点的垂直距离*/  
			var topYDis:Number=13*Math.sin(vRadian);  
			/**上顶点与目标点的水平距离*/  
			var topXDis:Number=13*Math.cos(vRadian);  
			/**下顶点与目标点的垂直距离*/  
			var botYDis:Number=13*Math.sin(hRadian);  
			/**下顶点与目标点的水平距离*/  
			var botXDis:Number=13*Math.cos(hRadian);  
			/**计算三角形上下顶点坐标*/  
			var topPointX:Number=toPoint.x-topXDis;  
			var topPointY:Number=toPoint.y-topYDis;  
			
			var botPointX:Number=toPoint.x-botXDis;  
			var botPointY:Number=toPoint.y+botYDis;  
			if(toPoint.x<fromPoint.x)  
			{  
				topPointX=toPoint.x+topXDis;  
				botPointX=toPoint.x+botXDis;  
			}  
			ui.graphics.beginFill(0xFECff0);  
			ui.graphics.moveTo(topPointX,topPointY);  
			ui.graphics.lineTo(toPoint.x,toPoint.y);  
			ui.graphics.lineTo(botPointX,botPointY);  
			ui.graphics.lineTo(topPointX,topPointY);
			
		}  
 

你可能感兴趣的:(Activiti)