skspatial.objects.Line

class skspatial.objects.Line(point: Union[numpy.ndarray, Sequence], direction: Union[numpy.ndarray, Sequence])[source]

A line in space.

The line is defined by a point and a direction vector.

Parameters
pointarray_like

Point on the line.

directionarray_like

Direction vector of the line.

kwargsdict, optional

Additional keywords passed to Vector.is_zero(). This method is used to ensure that the direction vector is not the zero vector.

Raises
ValueError

If the point and vector have different dimensions. If the vector is all zeros.

Examples

>>> from skspatial.objects import Line
>>> line = Line(point=[0, 0], direction=[3, 0])
>>> line
Line(point=Point([0, 0]), direction=Vector([3, 0]))
>>> line.direction
Vector([3, 0])

The direction can also be accessed with the vector attribute.

>>> line.vector
Vector([3, 0])

The line dimension is the dimension of the point and vector.

>>> line.dimension
2
>>> Line([0, 0], [1, 0, 0])
Traceback (most recent call last):
...
ValueError: The point and vector must have the same dimension.
>>> Line([1, 1], [0, 0])
Traceback (most recent call last):
...
ValueError: The vector must not be the zero vector.
Attributes
pointPoint

Point on the line.

directionVector

Unit direction vector.

vectorVector

Same as the direction.

dimensionint

Dimension of the line.

Methods

best_fit(points[, tol])

Return the line of best fit for a set of points.

distance_line(other)

Return the shortest distance from the line to another.

distance_point(point)

Return the distance from a point to the line.

from_points(point_a, point_b)

Instantiate a line from two points.

from_slope(slope, y_intercept)

Instantiate a 2D line from a slope and Y-intercept.

intersect_line(other, **kwargs)

Intersect the line with another.

is_coplanar(other, **kwargs)

Check if the line is coplanar with another.

plot_2d(ax_2d[, t_1, t_2])

Plot a 2D line.

plot_3d(ax_3d[, t_1, t_2])

Plot a 3D line.

project_point(point)

Project a point onto the line.

project_vector(vector)

Project a vector onto the line.

side_point(point)

Find the side of the line where a point lies.

to_point([t])

Return a point along the line using a parameter t.

transform_points(points)

Transform points to a one-dimensional coordinate system defined by the line.