Java Draw Arrow drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)

Here you can find the source of drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)

Description

Draw an arrow, useful for debug

License

Open Source License

Declaration

public static void drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;

public class Main {
    /** Draw an arrow, useful for debug */
    public static void drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2) {
        Graphics2D g = (Graphics2D) g2d.create();
        double dx = x2 - x1, dy = y2 - y1;
        double angle = Math.atan2(dy, dx);
        int len = (int) Math.sqrt(dx * dx + dy * dy);
        AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
        at.concatenate(AffineTransform.getRotateInstance(angle));
        g.transform(at);/*from   w  w w. java 2 s .com*/

        // Draw horizontal arrow starting in (0, 0)
        g.drawLine(0, 0, len, 0);
        g.fillPolygon(new int[] { len, len - 6, len - 6, len }, new int[] { 0, -6, 6, 0 }, 4);
    }
}

Related

  1. drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle)
  2. drawArrow(Graphics g, int x1, int y1, int x2, int y2, int lineWidth)
  3. drawArrow(Graphics g, Point from, Point to)
  4. drawArrow(Graphics g1, int x1, int y1, int x2, int y2, int lineWidth)
  5. drawArrow(Graphics2D g, Point2D point, double angle, int len)
  6. drawArrow(Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke)
  7. drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight)
  8. drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)
  9. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly)