# kornia.geometry.line#

class kornia.geometry.line.ParametrizedLine(origin, direction)[source]#

Class that describes a parametrize line.

A parametrized line is defined by an origin point $$o$$ and a unit direction vector $$d$$ such that the line corresponds to the set

$l(t) = o + t * d$
__init__(origin, direction)[source]#

Initializes a parametrized line of direction and origin.

Parameters

Example

>>> o = torch.tensor([0.0, 0.0])
>>> d = torch.tensor([1.0, 1.0])
>>> l = ParametrizedLine(o, d)

dim()[source]#

Return the dimension in which the line holds.

Return type

int

property direction: Tensor#

Return the line direction vector.

Return type

Tensor

distance(point)[source]#

Return the distance of a point to its projections onto the line.

Parameters

point (Tensor) – the point to calculate the distance into the line.

Return type

Tensor

intersect(plane, eps=1e-06)[source]#

Return the intersection point between the line and a given plane.

Parameters

plane (Hyperplane) – the plane to compute the intersection point.

Return type
Returns

• the lambda value used to compute the look at point.

• the intersected point.

property origin: Tensor#

Return the line origin point.

Return type

Tensor

point_at(t)[source]#

The point at $$t$$ along this line.

Parameters

t (Union[float, Tensor]) – step along the line.

Return type

Tensor

Returns

tensor with the point.

Example

>>> p0 = torch.tensor([0.0, 0.0])
>>> p1 = torch.tensor([1.0, 1.0])
>>> l = ParametrizedLine.through(p0, p1)
>>> p2 = l.point_at(0.1)

projection(point)[source]#

Return the projection of a point onto the line.

Parameters

point (Tensor) – the point to be projected.

Return type

Tensor

squared_distance(point)[source]#

Return the squared distance of a point to its projection onte the line.

Parameters

point (Tensor) – the point to calculate the distance onto the line.

Return type

Tensor

classmethod through(p0, p1)[source]#

Constructs a parametrized line going from a point $$p0$$ to $$p1$$.

Parameters
• p0 – tensor with first point $$(B, D)$$ where D is the point dimension.

• p1 – tensor with second point $$(B, D)$$ where D is the point dimension.

Example

>>> p0 = torch.tensor([0.0, 0.0])
>>> p1 = torch.tensor([1.0, 1.0])
>>> l = ParametrizedLine.through(p0, p1)

Return type

ParametrizedLine

kornia.geometry.line.fit_line(points, weights=None)[source]#

Fit a line from a set of points.

Parameters
• points (Tensor) – tensor containing a batch of sets of n-dimensional points. The expected shape of the tensor is $$(B, N, D)$$.

• weights (Optional[Tensor], optional) – weights to use to solve the equations system. The expected shape of the tensor is $$(B, N)$$. Default: None

Return type

ParametrizedLine

Returns

A tensor containing the direction of the fited line of shape $$(B, D)$$.

Example

>>> points = torch.rand(2, 10, 3)
>>> weights = torch.ones(2, 10)
>>> line = fit_line(points, weights)
>>> line.direction.shape
torch.Size([2, 3])

class kornia.geometry.line.Hyperplane(n, d)[source]#