CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-scikit-spatial

Spatial objects and computations based on NumPy arrays for 2D, 3D, and higher-dimensional geometric calculations.

Pending
Overview
Eval results
Files

linear-geometry.mddocs/

Linear Geometry

Lines, line segments, and planes with comprehensive geometric operations including projections, intersections, and distance calculations. Supports both infinite geometric objects and bounded segments with best-fit operations for data analysis.

Capabilities

Line

Represents an infinite line in N-dimensional space defined by a point and direction vector. Provides comprehensive geometric operations including projections, intersections, and transformations.

class Line:
    """
    An infinite line in N-dimensional space.
    
    Parameters:
    - point: array-like, a point on the line
    - direction: array-like, direction vector of the line
    """
    def __init__(self, point, direction): ...
    
    @classmethod
    def from_points(cls, point_a, point_b) -> 'Line':
        """
        Create line from two points.
        
        Parameters:
        - point_a: array-like, first point
        - point_b: array-like, second point
        
        Returns:
        Line passing through both points
        """
    
    @classmethod 
    def from_slope(cls, slope, y_intercept) -> 'Line':
        """
        Create 2D line from slope and y-intercept.
        
        Parameters:
        - slope: float, slope of the line
        - y_intercept: float, y-intercept value
        
        Returns:
        2D line with specified slope and intercept
        """
    
    @classmethod
    def best_fit(cls, points, tol=None, return_error=False, **kwargs) -> 'Line':
        """
        Find line of best fit for points.
        
        Parameters:
        - points: array-like, points to fit line to
        - tol: float, optional tolerance for singular value decomposition
        - return_error: bool, if True return fit error
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Best fit line, optionally with error value
        """
    
    @property
    def point(self) -> Point:
        """Point on the line."""
    
    @property
    def direction(self) -> Vector:
        """Direction vector of the line (same as vector)."""
    
    @property
    def vector(self) -> Vector:
        """Direction vector of the line (same as direction)."""
    
    @property
    def dimension(self) -> int:
        """Dimension of the line."""
    
    def is_coplanar(self, other, **kwargs) -> bool:
        """
        Check if coplanar with another line.
        
        Parameters:
        - other: Line, another line
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        True if lines are coplanar
        """
    
    def to_point(self, t=1) -> Point:
        """
        Get point along line using parameter t.
        
        Parameters:
        - t: float, parameter value (default: 1)
        
        Returns:
        Point at position: point + t * direction
        """
    
    def project_point(self, point) -> Point:
        """
        Project point onto line.
        
        Parameters:
        - point: array-like, point to project
        
        Returns:
        Projected point on the line
        """
    
    def project_points(self, points) -> Points:
        """
        Project multiple points onto line.
        
        Parameters:
        - points: array-like, points to project
        
        Returns:
        Projected points on the line
        """
    
    def project_vector(self, vector) -> Vector:
        """
        Project vector onto line.
        
        Parameters:
        - vector: array-like, vector to project
        
        Returns:
        Projected vector along line direction
        """
    
    def side_point(self, point) -> int:
        """
        Find side of line where point lies (2D only).
        
        Parameters:
        - point: array-like, 2D point
        
        Returns:
        1 if left side, -1 if right side, 0 if on line
        """
    
    def distance_point(self, point) -> np.float64:
        """
        Calculate distance from point to line.
        
        Parameters:
        - point: array-like, point
        
        Returns:
        Perpendicular distance to line
        """
    
    def distance_points(self, points) -> np.ndarray:
        """
        Calculate distances from points to line.
        
        Parameters:
        - points: array-like, multiple points
        
        Returns:
        Array of distances to line
        """
    
    def distance_line(self, other) -> np.float64:
        """
        Calculate distance between lines.
        
        Parameters:
        - other: Line, another line
        
        Returns:
        Minimum distance between lines
        """
    
    def intersect_line(self, other, check_coplanar=True, **kwargs) -> Point:
        """
        Find intersection with another line.
        
        Parameters:
        - other: Line, another line
        - check_coplanar: bool, check if lines are coplanar (default: True)
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Intersection point
        
        Raises:
        ValueError if lines are parallel or skew
        """
    
    def transform_points(self, points) -> np.ndarray:
        """
        Transform points to 1D coordinates along line.
        
        Parameters:
        - points: array-like, points to transform
        
        Returns:
        1D coordinate array along line
        """
    
    def contains_point(self, point, **kwargs) -> bool:
        """
        Check if line contains point.
        
        Parameters:
        - point: array-like, point to check
        - **kwargs: additional keywords passed to math.isclose
        
        Returns:
        True if point lies on line
        """
    
    def is_close(self, other, **kwargs) -> bool:
        """
        Check if close to another line.
        
        Parameters:
        - other: Line, another line
        - **kwargs: additional keywords passed to numpy.allclose
        
        Returns:
        True if lines are close
        """
    
    def sum_squares(self, points) -> np.float64:
        """
        Calculate sum of squared distances from points.
        
        Parameters:
        - points: array-like, points
        
        Returns:
        Sum of squared distances
        """
    
    def plot_2d(self, ax_2d, t_1=0, t_2=1, **kwargs):
        """
        Plot 2D line segment.
        
        Parameters:
        - ax_2d: matplotlib Axes, 2D plotting axes
        - t_1: float, start parameter (default: 0)
        - t_2: float, end parameter (default: 1)
        - **kwargs: additional keywords passed to plot
        """
    
    def plot_3d(self, ax_3d, t_1=0, t_2=1, **kwargs):
        """
        Plot 3D line segment.
        
        Parameters:
        - ax_3d: matplotlib Axes3D, 3D plotting axes
        - t_1: float, start parameter (default: 0)
        - t_2: float, end parameter (default: 1)
        - **kwargs: additional keywords passed to plot
        """

Usage Example:

from skspatial.objects import Line, Point

# Create line from point and direction
line = Line(point=[0, 0, 0], direction=[1, 1, 0])

# Create line from two points
line2 = Line.from_points([1, 2, 3], [4, 5, 6])

# Create 2D line from slope
line_2d = Line.from_slope(slope=2, y_intercept=1)

# Project point onto line
point = Point([5, 6, 7])
projected = line.project_point(point)

# Find intersection
intersection = line.intersect_line(line2)

# Line of best fit
import numpy as np
points = np.random.randn(20, 3)
best_fit_line = Line.best_fit(points)

Plane

Represents an infinite plane in N-dimensional space defined by a point and normal vector. Provides comprehensive operations for projections, intersections, and geometric analysis.

class Plane:
    """
    An infinite plane in N-dimensional space.
    
    Parameters:
    - point: array-like, a point on the plane
    - normal: array-like, normal vector to the plane
    """
    def __init__(self, point, normal): ...
    
    @classmethod
    def from_vectors(cls, point, vector_a, vector_b, **kwargs) -> 'Plane':
        """
        Create plane from point and two vectors.
        
        Parameters:
        - point: array-like, point on the plane
        - vector_a: array-like, first vector in plane
        - vector_b: array-like, second vector in plane
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Plane defined by point and span of vectors
        """
    
    @classmethod
    def from_points(cls, point_a, point_b, point_c, **kwargs) -> 'Plane':
        """
        Create plane from three points.
        
        Parameters:
        - point_a: array-like, first point
        - point_b: array-like, second point
        - point_c: array-like, third point
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Plane passing through all three points
        """
    
    @classmethod
    def best_fit(cls, points, tol=None, return_error=False, **kwargs) -> 'Plane':
        """
        Find plane of best fit for points.
        
        Parameters:
        - points: array-like, points to fit plane to
        - tol: float, optional tolerance for singular value decomposition
        - return_error: bool, if True return fit error
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Best fit plane, optionally with error value
        """
    
    @property
    def point(self) -> Point:
        """Point on the plane."""
    
    @property
    def normal(self) -> Vector:
        """Normal vector to the plane (same as vector)."""
    
    @property
    def vector(self) -> Vector:
        """Normal vector to the plane (same as normal)."""
    
    @property
    def dimension(self) -> int:
        """Dimension of the plane."""
    
    def cartesian(self) -> Tuple[np.float64, np.float64, np.float64, np.float64]:
        """
        Return Cartesian equation coefficients.
        
        Returns:
        Tuple (a, b, c, d) for equation ax + by + cz = d
        """
    
    def project_point(self, point) -> Point:
        """
        Project point onto plane.
        
        Parameters:
        - point: array-like, point to project
        
        Returns:
        Projected point on the plane
        """
    
    def project_points(self, points) -> Points:
        """
        Project multiple points onto plane.
        
        Parameters:
        - points: array-like, points to project
        
        Returns:
        Projected points on the plane
        """
    
    def project_vector(self, vector) -> Vector:
        """
        Project vector onto plane.
        
        Parameters:
        - vector: array-like, vector to project
        
        Returns:
        Projected vector in the plane
        """
    
    def project_line(self, line, **kwargs) -> Line:
        """
        Project line onto plane.
        
        Parameters:
        - line: Line, line to project
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Projected line in the plane
        """
    
    def distance_point_signed(self, point) -> np.float64:
        """
        Calculate signed distance from point to plane.
        
        Parameters:
        - point: array-like, point
        
        Returns:
        Signed distance (positive on normal side)
        """
    
    def distance_points_signed(self, points) -> np.ndarray:
        """
        Calculate signed distances from points to plane.
        
        Parameters:
        - points: array-like, multiple points
        
        Returns:
        Array of signed distances
        """
    
    def distance_point(self, point) -> np.float64:
        """
        Calculate absolute distance from point to plane.
        
        Parameters:
        - point: array-like, point
        
        Returns:
        Absolute distance to plane
        """
    
    def distance_points(self, points) -> np.ndarray:
        """
        Calculate absolute distances from points to plane.
        
        Parameters:
        - points: array-like, multiple points
        
        Returns:
        Array of absolute distances
        """
    
    def side_point(self, point) -> int:
        """
        Find side of plane where point lies.
        
        Parameters:
        - point: array-like, point
        
        Returns:
        1 if on normal side, -1 if opposite, 0 if on plane
        """
    
    def intersect_line(self, line, **kwargs) -> Point:
        """
        Find intersection with line.
        
        Parameters:
        - line: Line, line to intersect
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Intersection point
        
        Raises:
        ValueError if line is parallel to plane
        """
    
    def intersect_plane(self, other, **kwargs) -> Line:
        """
        Find intersection with another plane.
        
        Parameters:
        - other: Plane, another plane
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Intersection line
        
        Raises:
        ValueError if planes are parallel
        """
    
    def to_mesh(self, lims_x=(-1, 1), lims_y=(-1, 1)):
        """
        Generate mesh coordinates for plotting.
        
        Parameters:
        - lims_x: tuple, x-axis limits (default: (-1, 1))
        - lims_y: tuple, y-axis limits (default: (-1, 1))
        
        Returns:
        X, Y, Z mesh arrays for plotting
        """
    
    def to_points(self, **kwargs) -> Points:
        """
        Return points on the plane surface.
        
        Parameters:
        - **kwargs: additional keywords for mesh generation
        
        Returns:
        Points sampled on plane surface
        """
    
    def contains_point(self, point, **kwargs) -> bool:
        """
        Check if plane contains point.
        
        Parameters:
        - point: array-like, point to check
        - **kwargs: additional keywords passed to math.isclose
        
        Returns:
        True if point lies on plane
        """
    
    def plot_3d(self, ax_3d, lims_x=(-1, 1), lims_y=(-1, 1), **kwargs):
        """
        Plot 3D plane surface.
        
        Parameters:
        - ax_3d: matplotlib Axes3D, 3D plotting axes
        - lims_x: tuple, x-axis limits (default: (-1, 1))
        - lims_y: tuple, y-axis limits (default: (-1, 1))
        - **kwargs: additional keywords passed to plot_surface
        """

Usage Example:

from skspatial.objects import Plane, Line, Point

# Create plane from point and normal
plane = Plane(point=[0, 0, 0], normal=[0, 0, 1])

# Create plane from three points  
plane2 = Plane.from_points([0, 0, 0], [1, 0, 0], [0, 1, 0])

# Create plane from vectors
plane3 = Plane.from_vectors([0, 0, 0], [1, 0, 0], [0, 1, 0])

# Project point onto plane
point = Point([5, 6, 7])
projected = plane.project_point(point)  # Point([5, 6, 0])

# Find intersection with line
line = Line([0, 0, -5], [0, 0, 1])
intersection = plane.intersect_line(line)  # Point([0, 0, 0])

# Plane of best fit
import numpy as np
points = np.random.randn(50, 3)
best_fit_plane = Plane.best_fit(points)

LineSegment

Represents a finite line segment between two endpoints. Provides intersection testing and visualization for bounded linear geometry.

class LineSegment:
    """
    A finite line segment between two points.
    
    Parameters:
    - point_a: array-like, first endpoint
    - point_b: array-like, second endpoint
    """
    def __init__(self, point_a, point_b): ...
    
    @property
    def point_a(self) -> Point:
        """First endpoint of the segment."""
    
    @property
    def point_b(self) -> Point:
        """Second endpoint of the segment."""
    
    def contains_point(self, point, **kwargs) -> bool:
        """
        Check if point lies on the line segment.
        
        Parameters:
        - point: array-like, point to check
        - **kwargs: additional keywords passed to math.isclose
        
        Returns:
        True if point is on the segment between endpoints
        """
    
    def intersect_line_segment(self, other, **kwargs) -> Point:
        """
        Find intersection with another line segment.
        
        Parameters:
        - other: LineSegment, another line segment
        - **kwargs: additional keywords passed to numpy functions
        
        Returns:
        Intersection point
        
        Raises:
        ValueError if segments don't intersect
        """
    
    def plot_2d(self, ax_2d, **kwargs):
        """
        Plot 2D line segment.
        
        Parameters:
        - ax_2d: matplotlib Axes, 2D plotting axes
        - **kwargs: additional keywords passed to plot
        """
    
    def plot_3d(self, ax_3d, **kwargs):
        """
        Plot 3D line segment.
        
        Parameters:
        - ax_3d: matplotlib Axes3D, 3D plotting axes
        - **kwargs: additional keywords passed to plot
        """

Usage Example:

from skspatial.objects import LineSegment, Point

# Create line segment
segment = LineSegment([0, 0], [3, 4])

# Check if point is on segment
point = Point([1.5, 2])
on_segment = segment.contains_point(point)  # True

# Find intersection with another segment
segment2 = LineSegment([0, 3], [3, 0])
intersection = segment.intersect_line_segment(segment2)

Install with Tessl CLI

npx tessl i tessl/pypi-scikit-spatial

docs

basic-objects.md

curved-geometry.md

index.md

linear-geometry.md

measurement.md

transforms-plotting.md

tile.json