Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kornia Kornia Hyperplane

From Leeroopedia
Revision as of 15:21, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Kornia_Kornia_Hyperplane.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Vision, Geometry
Last Updated 2026-02-09 15:00 GMT

Overview

Provides the Hyperplane class (an nn.Module) for representing hyperplanes in n-dimensional space, along with fit_plane for fitting planes to 3D point sets via SVD.

Description

The plane.py module in the Kornia geometry library defines the Hyperplane class, inspired by Eigen's Hyperplane template. A hyperplane is represented by a normal vector (Vector3) and a scalar offset (Scalar) from the origin, such that for any point p on the plane, normal . p + offset = 0. The class supports signed and absolute distance computation from a point to the plane, point projection onto the plane, and construction from either a normal vector and a point (from_vector) or from two (2D) or three (3D) points (through). For the 3-point case, it uses cross products with an SVD fallback for near-degenerate configurations. The module also provides fit_plane, which fits a plane to a batch of 3D points using SVD on the mean-centered point set.

Usage

Import this module when you need to work with plane geometry in 3D space, such as plane fitting for point cloud segmentation, computing distances from points to planes, projecting points onto planes, or finding intersections between lines and planes.

Code Reference

Source Location

Signature

class Hyperplane(nn.Module):
    def __init__(self, n: Vector3, d: Scalar) -> None

    @property
    def normal(self) -> Vector3
    @property
    def offset(self) -> Scalar

    def abs_distance(self, p: Vector3) -> Scalar
    def signed_distance(self, p: Vector3) -> Scalar
    def projection(self, p: Vector3) -> Vector3

    @classmethod
    def from_vector(cls, n: Vector3, e: Vector3) -> "Hyperplane"

    @classmethod
    def through(
        cls, p0: torch.Tensor, p1: torch.Tensor,
        p2: Optional[torch.Tensor] = None,
    ) -> "Hyperplane"

def fit_plane(points: Vector3) -> Hyperplane

Import

from kornia.geometry.plane import Hyperplane, fit_plane

I/O Contract

Inputs (Hyperplane.__init__)

Name Type Required Description
n Vector3 Yes Normal vector of the hyperplane
d Scalar Yes Scalar distance (offset) from the origin

Outputs (Hyperplane.signed_distance)

Name Type Description
distance Scalar Signed distance from the point to the hyperplane

Inputs (Hyperplane.through)

Name Type Required Description
p0 torch.Tensor Yes First point, shape (*, 2) for 2D or (*, 3) for 3D
p1 torch.Tensor Yes Second point, same shape as p0
p2 torch.Tensor No Third point for 3D case, same shape as p0. None for 2D

Outputs (Hyperplane.through)

Name Type Description
plane Hyperplane Hyperplane passing through the given points

Inputs (fit_plane)

Name Type Required Description
points Vector3 Yes Batch of 3D points of shape (N, 3) or (B, N, 3)

Outputs (fit_plane)

Name Type Description
plane Hyperplane Fitted plane with normal and offset computed via SVD

Usage Examples

import torch
from kornia.geometry.plane import Hyperplane, fit_plane
from kornia.geometry.vector import Vector3, Scalar

# Create a hyperplane from normal and offset
normal = Vector3(torch.tensor([0., 0., 1.]))
offset = Scalar(torch.tensor(-5.0))
plane = Hyperplane(normal, offset)

# Compute signed distance from a point to the plane
point = Vector3(torch.tensor([1., 2., 10.]))
dist = plane.signed_distance(point)  # 10 - 5 = 5.0

# Create a plane through three 3D points
p0 = torch.tensor([0., 0., 0.])
p1 = torch.tensor([1., 0., 0.])
p2 = torch.tensor([0., 1., 0.])
plane_3pt = Hyperplane.through(p0, p1, p2)

# Project a point onto the plane
projected = plane.projection(point)

# Fit a plane to a set of 3D points using SVD
points = Vector3(torch.randn(100, 3))
fitted_plane = fit_plane(points)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment