planar.LineSegment – Line Segments — Planar v0.4 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Planar v0.4 documentation »

# `planar.LineSegment` – Line Segments

class `planar.` `LineSegment`(anchor, vector)

  Directed line segment between two points.

  Parameters: | anchor (Vec2) – The anchor, or starting point of the line segment. vector (Vec2) – The direction and magnitude vector of the line segment, must not be null.

  `almost_equals`(other)

    Return True if this line segment is approximately equal to another, within precision limits.

  `contains_point`(point)

    Return True if the specified point is on the line segment.

  `distance_to`(point)

    Return the distance between the given point and the line segment.

  classmethod `from_normal`(normal, offset, start_distance, end_distance)

    Create a line segment from a normal vector perpendicular to the line containing the segment, the offset distance from that line to origin, and the signed distances along that line from the projection of the origin to the start and end points of the segment respectively.

    Parameters: | normal (Vec2) – A non-null vector perpendicular to the line segment. Does not need to be unit-length. offset (float) – The signed distance from the line containing the segment to the origin. start_distance (float) – The signed distance along the segment’s containing line from the projection of the origin to the segment’s start (anchor) point. end_distance (float) – The signed distance along the containing line from the projection of the origin to the segment’s end point.

  classmethod `from_points`(points)

    Create a line segment from one or more collinear points. The first point is assumed to be the anchor. The order of the remaining points is unimportant, however they must all be collinear. The furthest point from the anchor determines the line segment’s vector.

    Parameters: | points – Iterable of at least 2 distinct points.

  `point_ahead`(point)

    Return True if the specified point is ahead of the endpoint of the line segment with respect to its direction.

  `point_behind`(point)

    Return True if the specified point is behind the anchor point with respect to the direction of the line segment.

  `point_left`(point)

    Return True if the specified point is in the space to the left of, but not behind the line segment.

  `point_right`(point)

    Return True if the specified point is in the space to the right of, but not behind the line segment.

  `project`(point)

    Compute the projection of a point onto the line segment. This is the closest point on the segment to the specified point.

    Parameters: | point (Vec2) – The point to project.

  `anchor`

    The anchor, or starting point of the line segment.

  `direction`

    Direction of the line as a unit vector. You may set this attribute to any non-null vector, however it will be normalized to unit-length.

  `end`

    The end point of the line sequence.

  `length`

    The distance between the line segments endpoints.

  `line`

    Return a containing line collinear with this line segment.

  `mid`

    The midpoint of the line segment (read-only).

  `normal`

    Normal unit vector perpendicular to the line. You may set this attribute to any non-null vector, however it will be normalized to unit-length. Modifying this will also affect the direction vector accordingly.

  `points`

    Return the two endpoints of the line segment as a sequence.

  `start`

    The starting point of the line segment. Alias for `anchor`

  `vector`

    The vector that comprises the length and direction of the line segment from its anchor point.

### Navigation

- index
- modules |
- next |
- previous |
- Planar v0.4 documentation »