I am required to write something similar to graphviz. I have already managed to draw the nodes so that they do not overlap and to connect their center with a quadratic Bezier curve, but I am facing the following problem with the directionality of a curved edge:
As you can see, the yellow little triangle is not quite nice. My code is the following:
g.setColor(Color.RED);
ArrowGraph arrow = graph.getArrows().get(0);
int x = (int)(arrow.getP1().getX() + arrow.getP2().getX()) / 2;
int y = (int)(arrow.getP1().getY() + arrow.getP2().getY()) / 2 + 50;
QuadCurve2D.Double curve = new QuadCurve2D.Double(arrow.getP1().getX() - 20, arrow.getP1().getY() - 20, x, y, arrow.getP2().getX() - 20, arrow.getP2().getY() - 20);
((Graphics2D)g).draw(curve);
int[] xPoints = new int[] {(int)arrow.getP2().getX() - 20, (int)arrow.getP2().getX() - 15, (int)arrow.getP2().getX() - 25};
int[] yPoints = new int[] {(int)arrow.getP2().getY() - 20, (int)arrow.getP2().getY() - 10, (int)arrow.getP2().getY() - 10};
g.setColor(Color.YELLOW);
g.fillPolygon(xPoints, yPoints, 3);
The coordinates that I know: the start and end point and the control point of the curve. The start and the end points are basically the centers of the nodes.
I would like to somehow adjust the triangle to the curve, so it's on the end of it (preferably at border of the node). Any idea how I could do that?