Exemplo n.º 1
0
 /**
  * Determines the orientation of a LineSegment relative to this segment. The concept of
  * orientation is specified as follows: Given two line segments A and L,
  *
  * <ul
  * <li>
  *   A is to the left of a segment L if A lies wholly in the closed half-plane lying to the left
  *   of L
  *   <li>A is to the right of a segment L if A lies wholly in the closed half-plane lying to the
  *       right of L
  *   <li>otherwise, A has indeterminate orientation relative to L. This happens if A is collinear
  *       with L or if A crosses the line determined by L.
  * </ul>
  *
  * @param seg the LineSegment to compare
  * @return 1 if <code>seg</code> is to the left of this segment
  * @return -1 if <code>seg</code> is to the right of this segment
  * @return 0 if <code>seg</code> is collinear to or crosses this segment
  */
 public int orientationIndex(LineSegment seg) {
   int orient0 = CGAlgorithms.orientationIndex(p0, p1, seg.p0);
   int orient1 = CGAlgorithms.orientationIndex(p0, p1, seg.p1);
   // this handles the case where the points are L or collinear
   if (orient0 >= 0 && orient1 >= 0) return Math.max(orient0, orient1);
   // this handles the case where the points are R or collinear
   if (orient0 <= 0 && orient1 <= 0) return Math.max(orient0, orient1);
   // points lie on opposite sides ==> indeterminate orientation
   return 0;
 }
Exemplo n.º 2
0
  /**
   * Computes the {@link Coordinate} that lies a given fraction along the line defined by this
   * segment and offset from the segment by a given distance. A fraction of <code>0.0</code> offsets
   * from the start point of the segment; a fraction of <code>1.0</code> offsets from the end point
   * of the segment. The computed point is offset to the left of the line if the offset distance is
   * positive, to the right if negative.
   *
   * @param segmentLengthFraction the fraction of the segment length along the line
   * @param offsetDistance the distance the point is offset from the segment (positive is to the
   *     left, negative is to the right)
   * @return the point at that distance and offset
   * @throws IllegalStateException if the segment has zero length
   */
  public Coordinate pointAlongOffset(double segmentLengthFraction, double offsetDistance) {
    // the point on the segment line
    double segx = p0.x + segmentLengthFraction * (p1.x - p0.x);
    double segy = p0.y + segmentLengthFraction * (p1.y - p0.y);

    double dx = p1.x - p0.x;
    double dy = p1.y - p0.y;
    double len = Math.sqrt(dx * dx + dy * dy);
    double ux = 0.0;
    double uy = 0.0;
    if (offsetDistance != 0.0) {
      if (len <= 0.0)
        throw new IllegalStateException("Cannot compute offset from zero-length line segment");

      // u is the vector that is the length of the offset, in the direction of the segment
      ux = offsetDistance * dx / len;
      uy = offsetDistance * dy / len;
    }

    // the offset point is the seg point plus the offset vector rotated 90 degrees CCW
    double offsetx = segx - uy;
    double offsety = segy + ux;

    Coordinate coord = new Coordinate(offsetx, offsety);
    return coord;
  }
Exemplo n.º 3
0
 /**
  * Gets the minimum X ordinate.
  *
  * @return the minimum X ordinate
  */
 public double minX() {
   return Math.min(p0.x, p1.x);
 }
Exemplo n.º 4
0
 /**
  * Computes the angle that the vector defined by this segment makes with the X-axis. The angle
  * will be in the range [ -PI, PI ] radians.
  *
  * @return the angle this segment makes with the X-axis (in radians)
  */
 public double angle() {
   return Math.atan2(p1.y - p0.y, p1.x - p0.x);
 }
Exemplo n.º 5
0
 /**
  * Gets the maximum Y ordinate.
  *
  * @return the maximum Y ordinate
  */
 public double maxY() {
   return Math.max(p0.y, p1.y);
 }
Exemplo n.º 6
0
 /**
  * Gets the minimum Y ordinate.
  *
  * @return the minimum Y ordinate
  */
 public double minY() {
   return Math.min(p0.y, p1.y);
 }
Exemplo n.º 7
0
 /**
  * Gets the maximum X ordinate.
  *
  * @return the maximum X ordinate
  */
 public double maxX() {
   return Math.max(p0.x, p1.x);
 }