/** * Returns the index of the segment at the given distance along the path. */ public int segmentAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return -1; } if (upperIndex == 0) { // Length was probably zero, so return the upper segment. PathSegment upper = (PathSegment) segments.get(upperIndex); return upper.getIndex(); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); return lower.getIndex(); }
/** * Returns the index of the segment at the given distance along the path. */ public int segmentAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return -1; } if (upperIndex == 0) { // Length was probably zero, so return the upper segment. PathSegment upper = (PathSegment) segments.get(upperIndex); return upper.getIndex(); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); return lower.getIndex(); }
/** * Returns the index of the segment at the given distance along the path. */ public int segmentAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return -1; } if (upperIndex == 0) { // Length was probably zero, so return the upper segment. PathSegment upper = (PathSegment) segments.get(upperIndex); return upper.getIndex(); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); return lower.getIndex(); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the slope of the path at the specified length. * @param length The length along the path * @return the angle in radians, in the range [-{@link Math#PI}, * {@link Math#PI}]. */ public float angleAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return 0f; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the angle between the first // and second segments. upperIndex = 1; } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Compute the slope. return (float) Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }
/** * Returns the point that is at the given length along the path. * @param length The length along the path * @return The point at the given length */ public Point2D pointAtLength(float length) { int upperIndex = findUpperIndex(length); if (upperIndex == -1) { // Length is off the end of the path. return null; } PathSegment upper = (PathSegment) segments.get(upperIndex); if (upperIndex == 0) { // Length was probably zero, so return the upper point. return new Point2D.Float(upper.getX(), upper.getY()); } PathSegment lower = (PathSegment) segments.get(upperIndex - 1); // Now work out where along the line would be the length. float offset = length - lower.getLength(); // Compute the slope. double theta = Math.atan2(upper.getY() - lower.getY(), upper.getX() - lower.getX()); float xPoint = (float) (lower.getX() + offset * Math.cos(theta)); float yPoint = (float) (lower.getY() + offset * Math.sin(theta)); return new Point2D.Float(xPoint, yPoint); }