1234567891011121314151617181920212223242526272829303132333435 |
- package View;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.awt.Shape;
- import java.awt.geom.AffineTransform;
- /**
- * Contains helper functions for the views.
- * @author kolja
- *
- */
- public class RenderHelper {
- /**
- * creates an arrow shape to draw it, for example as an edge.
- * @param fromPt the starting point of the arrow
- * @param toPt the destination point of the arrow
- * @return the shape
- */
- public static Shape createArrowShape(Point fromPt, Point toPt) {
- Polygon arrowPolygon = new Polygon();
- arrowPolygon.addPoint(-3,6);
- arrowPolygon.addPoint(3,0);
- arrowPolygon.addPoint(-3,-6);
- arrowPolygon.addPoint(-3,6);
- double rotate = Math.atan2( ( toPt.y - fromPt.y ) , ( toPt.x - fromPt.x ) );
- AffineTransform transform = new AffineTransform();
- transform.translate(toPt.x, toPt.y);
- transform.rotate(rotate);
- return transform.createTransformedShape(arrowPolygon);
- }
- }
|