Tom Chiverton wrote:
> My maths has left me - given a line from x1,y1 to x2,y2 how do I draw an 
> arrow
> pointing from x1,y1 to x2,y2, with it's tip on x2,y2 ?

private function drawArrow():void {
deDupe(); // de-duplicate any extra points from double click
if (xPoints.length>1) {
var arrowWidth:Number = 4;
var arrowHeight:Number = 8;
mapGraphics.name="redline";     
mapGraphics.graphics.lineStyle(2, drawColor);                           
mapGraphics.graphics.moveTo(xPoints[0],yPoints[0]);                             
for (var i:int=1; i < xPoints.length; i++) {
        mapGraphics.graphics.lineTo(xPoints[i],yPoints[i]);     
}
// now draw the arrow
// we only care about last two points
var angle:Number= 
Math.atan2(yPoints[yPoints.length-1]-yPoints[yPoints.length-2],xPoints[xPoints.length-1]-xPoints[xPoints.length-2]);
mapGraphics.graphics.moveTo(xPoints[xPoints.length-1],yPoints[yPoints.length-1]);
mapGraphics.graphics.lineTo(xPoints[xPoints.length-1]-arrowHeight*Math.cos(angle)-arrowWidth*Math.sin(angle),yPoints[yPoints.length-1]-arrowHeight*Math.sin(angle)+arrowWidth*Math.cos(angle));
mapGraphics.graphics.lineTo(xPoints[xPoints.length-1],yPoints[yPoints.length-1]);
mapGraphics.graphics.lineTo(xPoints[xPoints.length-1]-arrowHeight*Math.cos(angle)+arrowWidth*Math.sin(angle),yPoints[yPoints.length-1]-arrowHeight*Math.sin(angle)-arrowWidth*Math.cos(angle));
mapImage.addChild(mapGraphics);
} //if
}


Reply via email to