예제 #1
0
  /**
   * Compute the projection of a point onto the line determined by this line segment.
   *
   * <p>Note that the projected point may lie outside the line segment. If this is the case, the
   * projection factor will lie outside the range [0.0, 1.0].
   */
  public Coordinate project(Coordinate p) {
    if (p.equals(p0) || p.equals(p1)) return new Coordinate(p);

    double r = projectionFactor(p);
    Coordinate coord = new Coordinate();
    coord.x = p0.x + r * (p1.x - p0.x);
    coord.y = p0.y + r * (p1.y - p0.y);
    return coord;
  }
예제 #2
0
 /**
  * Computes the {@link Coordinate} that lies a given fraction along the line defined by this
  * segment. A fraction of <code>0.0</code> returns the start point of the segment; a fraction of
  * <code>1.0</code> returns the end point of the segment. If the fraction is < 0.0 or > 1.0 the
  * point returned will lie before the start or beyond the end of the segment.
  *
  * @param segmentLengthFraction the fraction of the segment length along the line
  * @return the point at that distance
  */
 public Coordinate pointAlong(double segmentLengthFraction) {
   Coordinate coord = new Coordinate();
   coord.x = p0.x + segmentLengthFraction * (p1.x - p0.x);
   coord.y = p0.y + segmentLengthFraction * (p1.y - p0.y);
   return coord;
 }