Java examples for 2D Graphics:Path
get Rounded General Path From Points
//package com.java2s; import java.awt.Point; import java.awt.geom.GeneralPath; import java.util.List; public class Main { public static GeneralPath getRoundedGeneralPathFromPoints(List<Point> l) { l.add(l.get(0));/*from w ww . j ava2 s.c o m*/ l.add(l.get(1)); GeneralPath p = new GeneralPath(); p.moveTo(l.get(0).x, l.get(0).y); for (int pointIndex = 1; pointIndex < l.size() - 1; pointIndex++) { Point p1 = l.get(pointIndex - 1); Point p2 = l.get(pointIndex); Point p3 = l.get(pointIndex + 1); Point mPoint = calculatePoint(p1, p2); p.lineTo(mPoint.x, mPoint.y); mPoint = calculatePoint(p3, p2); p.curveTo(p2.x, p2.y, p2.x, p2.y, mPoint.x, mPoint.y); } return p; } private static Point calculatePoint(Point p1, Point p2) { float arcSize = 10; double d1 = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2)); double per = arcSize / d1; double d_x = (p1.x - p2.x) * per; double d_y = (p1.y - p2.y) * per; int xx = (int) (p2.x + d_x); int yy = (int) (p2.y + d_y); return new Point(xx, yy); } }