this.g.drawLine(a[0], a[1], b[0], b[1]);
double arrowWidth = rendererModel.getArrowHeadWidth() / rendererModel.getScale();
double lenghtOfArrow = Math.sqrt(Math.pow(Math.abs(line.startX - line.endX), 2) + Math.pow(Math.abs(line.startY - line.endY), 2));
double fractionOfHead = arrowWidth / lenghtOfArrow;
//headpoint is a line on the arrow arrowWidth away from end
Point2d headPoint = new Point2d();
if (line.startX < line.endX)
headPoint.x = line.startX + (line.endX - line.startX) * (fractionOfHead);
else
headPoint.x = line.endX + (line.startX - line.endX) * (1 - fractionOfHead);
if (line.startY < line.endY)
headPoint.y = line.startY + (line.endY - line.startY) * (fractionOfHead);
else
headPoint.y = line.endY + (line.startY - line.endY) * (1 - fractionOfHead);
//rotate headpoint in both directions to get end points of arrow
double relativex = headPoint.x - line.startX;
double relativey = headPoint.y - line.startY;
double angle = Math.PI / 6;
double costheta = Math.cos(angle);
double sintheta = Math.sin(angle);
Point2d firstArrowPoint = new Point2d();
firstArrowPoint.x = relativex * costheta - relativey * sintheta + line.startX;
firstArrowPoint.y = relativex * sintheta + relativey * costheta + line.startY;
int[] firstArrowPointCoords = this.transformPoint(firstArrowPoint.x, firstArrowPoint.y);
this.g.drawLine(a[0], a[1], firstArrowPointCoords[0], firstArrowPointCoords[1]);
angle = -Math.PI / 6;
costheta = Math.cos(angle);
sintheta = Math.sin(angle);
Point2d secondArrowPoint = new Point2d();
secondArrowPoint.x = relativex * costheta - relativey * sintheta + line.startX;
secondArrowPoint.y = relativex * sintheta + relativey * costheta + line.startY;
int[] secondArrowPointCoords = this.transformPoint(secondArrowPoint.x, secondArrowPoint.y);
this.g.drawLine(a[0], a[1], secondArrowPointCoords[0], secondArrowPointCoords[1]);
this.g.setStroke(savedStroke);