Java Draw Arrow drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)

Here you can find the source of drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill)

Description

draw Arrow Head

License

Open Source License

Declaration

public static void drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill) 

Method Source Code

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

import java.awt.Graphics;

public class Main {
    public static void drawArrowHead(Graphics g, double c1, double c2, double phi, int l, int grad, boolean fill) {
        phi = (phi + 180) % 360;//from w w w.j av  a 2  s.  c  o m
        int px = (int) (c1 + Math.cos((2 * Math.PI * (phi + grad) / 360)) * l);
        int py = (int) (c2 - Math.sin((2 * Math.PI * (phi + grad) / 360)) * l);
        int px2 = (int) (c1 + Math.cos((2 * Math.PI * (phi - grad) / 360)) * l);
        int py2 = (int) (c2 - Math.sin((2 * Math.PI * (phi - grad) / 360)) * l);
        if (fill) {
            g.fillPolygon(new int[] { (int) c1, px, px2 }, new int[] { (int) c2, py, py2 }, 3);
        } else {
            g.drawLine((int) c1, (int) c2, px, py);
            g.drawLine((int) c1, (int) c2, px2, py2);
        }

    }
}

Related

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