/** * Computes the unitary normal vector of a segment * @param x1 Starting point of the segment * @param y1 Starting point of the segment * @param x2 Ending point of the segment * @param y2 Ending point of the segment * @return */ public Point2D.Double normal(int x1,int y1,int x2, int y2) { double nx,ny; if (x1 == x2) { nx = Math.signum(y2-y1); ny = 0; } else { double f = (y2-y1)/(double)(x2-x1); nx = f*Math.signum(x2-x1)/Math.sqrt(1+f*f); ny = -1*Math.signum(x2-x1)/Math.sqrt(1+f*f); } return new Point2D.Double(nx,ny); }