Java examples for 2D Graphics:Shape
create Arrow Shape
/*//from w w w .ja v a2s.c o m * Copyright (C) 2013 by Array Systems Computing Inc. http://www.array.ca * * This program 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. * This program 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 this program; if not, see http://www.gnu.org/licenses/ */ //package com.java2s; public class Main { public static void createArrow(int x, int y, int xx, int yy, int i1, double[] ipts) { ipts[0] = x; ipts[1] = y; ipts[2] = xx; ipts[3] = yy; final double d = xx - x; final double d1 = -(yy - y); double d2 = Math.sqrt(d * d + d1 * d1); final double d3; final double size = 2.0; if (d2 > (3.0 * i1)) d3 = i1; else d3 = d2 / 3.0; if (d2 < 1.0) d2 = 1.0; if (d2 >= 1.0) { final double d4 = (d3 * d) / d2; final double d5 = -((d3 * d1) / d2); final double d6 = (double) xx - size * d4; final double d7 = (double) yy - size * d5; ipts[4] = (int) (d6 - d5); ipts[5] = (int) (d7 + d4); ipts[6] = (int) (d6 + d5); ipts[7] = (int) (d7 - d4); } } }