Skip to main content

2D Conehull

This package uses the quickhull algorithm to find the convex hull of a point set, but with the added option of restricting the set of halfplanes we intersect over to only those with normals lying in a given convex cone.

Features

  • Cone-Constrained Hull: The cone feature computes the intersection of halfplanes whose outward normals lie between two specified direction vectors. This creates a larger (unbounded) region that contains the original convex hull.
  • Visualizations: View a step-by-step visualization of the algorithm.
  • Samplers: For convenience we include simple ways of creating point sets, by inputting either an implicit (in)equality or a parametrization.

Basic Usage

import numpy as np

from conehull import conehull
from conehull.view import plot_hull

points = np.array([
    [ 3.0, -4.0],
    [-1.0,  0.0],
    [ 3.0,  5.0],
    [ 4.5,  1.0],
    [-6.0, -2.0],
    [ 0.0,  4.0],
    [ 5.0,  2.0],
    [-2.0, -5.0],
    [ 1.0,  2.0],
    [ 2.0,  6.0],
    [-5.5,  1.5],
    [ 6.0, -1.0],
    [-3.0,  7.0],
    [ 3.0,  0.0],
    [ 2.0, -2.5],
    [ 4.0,  0.0],
    [-7.0,  3.0],
    [-4.0, -0.5],
])
cone = np.array([[1, 0], [0, 1]])

hull = conehull(points, cone=cone)

# plot_hull is just a convenience wrapper around pyplot
plot_hull(hull, points, cone=cone, show_convex_hull=True, 
                title="Cone hull with standard convex hull comparison")

Samplers

import numpy as np
from conehull import conehull
from conehull.sampler import sample_implicit_region

F = lambda X, Y: X**2 + 2*Y**2 - 1
pts = sample_implicit_region(F, n_samples=5000)

cone = np.array([[-0.9, 0.2], [0.4, 0.9]])
hull = conehull(pts, cone)
plot_hull(hull, pts, cone=cone, show_convex_hull=True, save_path='elliptic_disk.jpg',
                title=r"Elliptic Disk: $x^2 + 2y^2 \leq 1$")

Visualization Modes

# Import visualization functions
from conehull.view import (
    conehull_animated,
    conehull_step_by_step, 
    conehull_jupyter,
    plot_hull
)

# 1. Animated visualization - auto-playing GIF/video
# Creates a smooth animation showing algorithm steps
conehull_animated(points, cone=cone, save_path="animation.gif", interval=800)

# 2. Step-by-step interactive viewer - returns navigation functions
# Best for understanding algorithm mechanics step by step
hull, frames, show_frame = conehull_step_by_step(points, cone=cone)

# Use the returned show_frame function to navigate:
show_frame(0)    # Show first step
show_frame(5)    # Jump to step 5
show_frame(-1)   # Show final result

# 3. Jupyter widget - interactive controls in notebooks
# Returns a widget object with navigation buttons and sliders
if 'ipywidgets' in globals():  # Only works in Jupyter
    viewer = conehull_jupyter(points, cone=cone)
    viewer.show()  # Display the interactive widget

# 4. Static hull plot - simple visualization with comparison option
plot_hull(hull=cone_hull, points=points, cone=cone, 
          show_convex_hull=True, save_path="comparison.png")

Configurable Bounding Box

Since the hull is unbounded for any nontrivial cone, we use a bounding box. The cone_bounds parameter controls how the unbounded cone hull is clipped:

# Default: margin = 2.0 times data range
cone_hull = conehull(points, cone=cone)

# Custom margin multiplier
cone_hull = conehull(points, cone=cone, cone_bounds=5.0)

# Explicit bounds: [x_min, x_max, y_min, y_max]
cone_hull = conehull(points, cone=cone, cone_bounds=[-10, 10, -10, 10])

# Alternative format: [[x_min, y_min], [x_max, y_max]]
cone_hull = conehull(points, cone=cone, cone_bounds=[[-10, -10], [10, 10]])

Files

  • _geometry.py - Basic geometric operations like point-to-line distances and determining which side of a line points are on. Also handles sorting hull points in counterclockwise order.
  • _conehull.py - Implements the QuickHull algorithm for both standard and cone-constrained convex hulls. Contains the main conehull() function and recursive hull construction logic.
  • _cone_intersection.py - Transforms standard convex hulls into cone hulls by filtering halfplanes based on cone constraints. Computes intersections within configurable bounding boxes.
  • view.py - Visualization tools including step-by-step animations, interactive Jupyter widgets, and static plotting. Supports both automated playback and manual navigation of algorithm steps.
  • sampler.py - Generates test point datasets from mathematical functions. Supports parametric curves, implicit equations, and region sampling for creating diverse test cases.

Quickhull

For animations, we use our own Quickhull implementation (pure Python) so we can show step-by-step execution; it’s intentionally simple but becomes slow on datasets with thousands of points.

When no animation is needed, this package uses SciPy’s scipy.spatial.ConvexHull, which wraps the Qhull library by C. Bradford Barber and Hannu Huhdanpaa. Barber, Dobkin, and Huhdanpaa introduced the widely used n-dimensional Quickhull in their 1996 ACM TOMS paper, The Quickhull Algorithm for Convex Hulls.

Metadata

Release files for conehull 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for conehull 1.0.1
File Size Uploaded
conehull-1.0.1.tar.gz 1.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for conehull 1.0.1
File Interpreter ABI Platform
conehull-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / conehull-1.0.1.tar.gz

Download URL conehull-1.0.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
548a179bd15c2a8508d00695a74e511f0a7cec9c61a5739c3c1809fa20923299
BLAKE2b-256 checksum
How to use checksums
88f44959a335654d6a472a1ed8c7ba6b0175a91090dcf3f7f5b37403a496d386
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / conehull-1.0.1-py3-none-any.whl

Download URL conehull-1.0.1-py3-none-any.whl
Size 32.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13f244a4a882d9001ddbf95ffcc60ad4df1603a3515be66e9f1e0a3974f648c2
BLAKE2b-256 checksum
How to use checksums
bb918e5cb876e26d1bc70bffb5a8fc690df82b2336b1b696c51fb04dd201de84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page