/** * Calculate the normal vector at a given vertex. * * @param pt * the vertex. * @param pointList * the {@link PointList} in which to search. * @return the unit normal vector of the vertex. */ public Point2dImpl calculateNormal(Point2d pt, PointList pointList) { return calculateNormal(pointList.points.indexOf(pt), pointList); }
/** * Calculate a normal line for a given vertex. * * @param pt * the vertex * @param pointList * the {@link PointList} in which to search/ * @param scale * The scaling to apply to the line; a scale of 1.0 will lead to * a line that is 2.0 units long (1.0 either side of the vertex). * @return the normal line. */ public Line2d calculateNormalLine(Point2d pt, PointList pointList, float scale) { final Point2dImpl normal = calculateNormal(pointList.points.indexOf(pt), pointList); if (normal == null) return null; final float nx = normal.x; final float ny = normal.y; final Point2dImpl start = new Point2dImpl((nx * scale) + pt.getX(), (ny * scale) + pt.getY()); final Point2dImpl end = new Point2dImpl(-(nx * scale) + pt.getX(), -(ny * scale) + pt.getY()); return new Line2d(start, end); }