Planar logo

Previous topic

planar.Line – Infinite Lines

Next topic

planar.LineSegment – Line Segments

This Page

planar.Ray – Infinite Semi-Lines

class planar.Ray(anchor, direction)

Directed ray anchored by a single point.

Parameters:
  • anchor (Vec2) – The anchor, or starting point of the ray.
  • direction (Vec2) – The direction of the ray as a vector, must not be null. Does not need to be unit-length.
almost_equals(other)

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

contains_point(point)

Return True if the specified point is on the ray.

distance_to(point)

Return the distance between the given point and the ray.

classmethod from_points(points)

Create a ray from two or more collinear points. The direction of the ray is derived from the first two distinct points, with the first point assumed to be the anchor. The order of the remaining points is unimportant, however they must all be on the ray.

Parameters:
  • points – Iterable of at least 2 distinct points.
point_behind(point)

Return True if the specified point is behind the anchor point with respect to the direction of the ray. In other words, the angle between the ray direction and the vector pointing from the ray’s anchor to the given point is greater than 90 degrees.

point_left(point)

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

point_right(point)

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

project(point)

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

Parameters:
  • point (Vec2) – The point to project.
anchor

The anchor, or starting point of the ray.

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.

line

Return a line collinear with this ray.

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 two distinct points along the ray, such that ray.from_points(ray.points) will construct an equivalent ray. The first point returned is always the anchor point.

start

The starting point of the ray. Alias for anchor