Java examples for 2D Graphics:Path
is Same Direction
import java.awt.geom.PathIterator; import java.awt.geom.GeneralPath; import java.awt.geom.Point2D; import java.awt.geom.Line2D; import java.awt.Point; public class Main{ public static boolean isSameDirection(GeneralPath p1, GeneralPath p2, double radAngleTollerance) { //FIX ME : Really not sure about this logic. //two paths are the same direction if the lines drawn from their //end points are in the same direction. //Remember that 360 and 1 are similar angles. final double tollerance = radAngleTollerance; double a1 = getAverageAngle(p1) + tollerance; double a2 = getAverageAngle(p2) + tollerance; a1 = a1 % (2 * Math.PI);/*w w w.ja va2s . c om*/ a2 = a2 % (2 * Math.PI); return (Math.abs(a1 - a2) < tollerance); } public static double getAverageAngle(GeneralPath path) { double seg[] = new double[6]; PathIterator pi = path.getPathIterator(null); int segType = pi.currentSegment(seg); return GeoUtils.getAngle(seg[0], seg[1], path.getCurrentPoint() .getX(), path.getCurrentPoint().getY()); } }