kornia.geometry.line#

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

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)#

Initializes a parametrized line of direction and origin.

Parameters:
  • origin (Tensor) – any point on the line of any dimension.

  • direction (Tensor) – the normalized vector direction of any dimension.

Example

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

Return the dimension in which the line holds.

Return type:

int

property direction: Tensor#

Return the line direction vector.

distance(point)#

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-6)#

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

Parameters:

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

Return type:

Tuple[Tensor, Tensor]

Returns:

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

  • the intersected point.

property origin: Tensor#

Return the line origin point.

point_at(t)#

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)#

Return the projection of a point onto the line.

Parameters:

point (Tensor) – the point to be projected.

Return type:

Tensor

squared_distance(point)#

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)#

Constructs a parametrized line going from a point \(p0\) to \(p1\).

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

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

Return type:

ParametrizedLine

Example

>>> p0 = torch.tensor([0.0, 0.0])
>>> p1 = torch.tensor([1.0, 1.0])
>>> l = ParametrizedLine.through(p0, p1)
kornia.geometry.line.fit_line(points, weights=None)#

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)#

Interactive Demo#