Java Draw Arrow drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly)

Here you can find the source of drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly)

Description

draw Arrow Line

License

Open Source License

Declaration

public static void drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly) 

Method Source Code


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

import java.awt.Graphics;

public class Main {
    public static void drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int d, int h, boolean capOnly) {
        int dx = x2 - x1, dy = y2 - y1;
        double D = Math.sqrt(dx * dx + dy * dy);
        double xm = D - d, xn = xm, ym = h, yn = -h, x;
        double sin = dy / D, cos = dx / D;

        x = xm * cos - ym * sin + x1;/*from w  ww.java  2s  . c om*/
        ym = xm * sin + ym * cos + y1;
        xm = x;

        x = xn * cos - yn * sin + x1;
        yn = xn * sin + yn * cos + y1;
        xn = x;

        int[] xpoints = { x2, (int) xm, (int) xn };
        int[] ypoints = { y2, (int) ym, (int) yn };

        if (!capOnly)
            g.drawLine(x1, y1, x2, y2);
        g.fillPolygon(xpoints, ypoints, 3);
    }
}

Related

  1. drawArrow(Graphics2D g, Point2D point, double angle, int len)
  2. drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)
  3. drawArrow(Graphics2D g2d, int xCenter, int yCenter, int x, int y, float stroke)
  4. drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight)
  5. drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)
  6. drawArrowLine(Graphics g, int x1, int y1, int x2, int y2, int dist, boolean arrowLeft, boolean arrowRight)
  7. drawDoubleHeadedArrow(final Graphics aG, final int aX1, final int aY, final int aX2)
  8. drawHorizontalArrow(Graphics g, Rectangle r, boolean direction)