Package toxi.geom

Class Line2D

java.lang.Object
toxi.geom.Line2D

public class Line2D extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • splitIntoSegments

      public static final List<Vec2D> splitIntoSegments(Vec2D a, Vec2D b, float stepLength, List<Vec2D> segments, boolean addFirst)
      Splits the line between A and B into segments of the given length, starting at point A. The tweened points are added to the given result list. The last point added is B itself and hence it is likely that the last segment has a shorter length than the step length requested. The first point (A) can be omitted and not be added to the list if so desired.
      Parameters:
      a - start point
      b - end point (always added to results)
      stepLength - desired distance between points
      segments - existing array list for results (or a new list, if null)
      addFirst - false, if A is NOT to be added to results
      Returns:
      list of result vectors
    • classifyPoint

      public float classifyPoint(ReadonlyVec2D p)
      Computes the dot product of these 2 vectors: line start -> point and the perpendicular line direction. If the result is negative
      Parameters:
      p -
      Returns:
      classifier float
    • closestPointTo

      public Vec2D closestPointTo(ReadonlyVec2D p)
      Computes the closest point on this line to the point given.
      Parameters:
      p - point to check against
      Returns:
      closest point on the line
    • copy

      public Line2D copy()
    • distanceToPoint

      public float distanceToPoint(ReadonlyVec2D p)
    • distanceToPointSquared

      public float distanceToPointSquared(ReadonlyVec2D p)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getBoundingCircle

      public Circle getBoundingCircle()
    • getBounds

      public Rect getBounds()
      Returns the line's bounding rect.
      Returns:
      bounding rect
    • getDirection

      public Vec2D getDirection()
    • getHeading

      public float getHeading()
    • getLength

      public float getLength()
    • getLengthSquared

      public float getLengthSquared()
    • getMidPoint

      public Vec2D getMidPoint()
    • getNormal

      public Vec2D getNormal()
    • hasEndPoint

      public boolean hasEndPoint(Vec2D p)
    • hashCode

      public int hashCode()
      Computes a hash code ignoring the directionality of the line.
      Overrides:
      hashCode in class Object
      Returns:
      hash code
      See Also:
    • hashCodeWithDirection

      public int hashCodeWithDirection()
      Computes the hash code for this instance taking directionality into account. A->B will produce a different hash code than B->A. If directionality is not required or desired use the default hashCode() method.
      Returns:
      hash code
      See Also:
    • intersectLine

      public Line2D.LineIntersection intersectLine(Line2D l)
      Computes intersection between this and the given line. The returned value is a Line2D.LineIntersection instance and contains both the type of intersection as well as the intersection points (if existing). The intersection points are ALWAYS computed for the types INTERSECTING and NON_INTERSECTING. In the latter case the points will lie outside the two given line segments and constitute the intersections of the infinite versions of each line. Based on: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
      Parameters:
      l - line to intersect with
      Returns:
      intersection result
    • offsetAndGrowBy

      public Line2D offsetAndGrowBy(float offset, float scale, Vec2D ref)
    • scaleLength

      public Line2D scaleLength(float scale)
    • set

      public Line2D set(Vec2D a, Vec2D b)
    • splitIntoSegments

      public List<Vec2D> splitIntoSegments(List<Vec2D> segments, float stepLength, boolean addFirst)
    • toRay2D

      public Ray2D toRay2D()
    • toString

      public String toString()
      Overrides:
      toString in class Object