Java Draw Arrow drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle)

Here you can find the source of drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle)

Description

draw Arrow

License

Open Source License

Declaration

static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This file is part of logisim-evolution.
 *
 *   logisim-evolution is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   logisim-evolution is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with logisim-evolution.  If not, see <http://www.gnu.org/licenses/>.
 *
 *   Original code by Carl Burch (http://www.cburch.com), 2011.
 *   Subsequent modifications by :/*from w  w  w .  j  a  v  a2 s .c  o  m*/
 *     + Haute ?cole Sp?cialis?e Bernoise
 *       http://www.bfh.ch
 *     + Haute ?cole du paysage, d'ing?nierie et d'architecture de Gen?ve
 *       http://hepia.hesge.ch/
 *     + Haute ?cole d'Ing?nierie et de Gestion du Canton de Vaud
 *       http://www.heig-vd.ch/
 *   The project is currently maintained by :
 *     + REDS Institute - HEIG-VD
 *       Yverdon-les-Bains, Switzerland
 *       http://reds.heig-vd.ch
 *******************************************************************************/

import java.awt.Graphics;

public class Main {
    static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
        double offs = headAngle * Math.PI / 180.0;
        double angle = Math.atan2(y0 - y1, x0 - x1);
        int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
                x1 + (int) (headLength * Math.cos(angle - offs)) };
        int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
                y1 + (int) (headLength * Math.sin(angle - offs)) };
        g.drawLine(x0, y0, x1, y1);
        g.drawPolyline(xs, ys, 3);
    }
}

Related

  1. draw_nav1_backward_arrow(Graphics2D g2, int x, int y, int length, int base_width)
  2. draw_nav2_backward_arrow(Graphics2D g2, int x, int y, int length, int base_width)
  3. drawArrow(final Graphics2D g, final int x1, final int y1, final int x2, final int y2)
  4. drawArrow(Graphics g, double x0, double y0, double x1, double y1, double weight)
  5. drawArrow(Graphics g, int x1, int y1, int x2, int y2, int lineWidth)
  6. drawArrow(Graphics g, Point from, Point to)
  7. drawArrow(Graphics g1, int x1, int y1, int x2, int y2, int lineWidth)
  8. drawArrow(Graphics2D g, Point2D point, double angle, int len)