Skip to main content

GridPath is a Python library for calculating grid-based paths and intersection points between two coordinates. It's particularly useful for applications requiring precise path tracking on a grid system, such as robotics, game development, or computer graphics.

Project description

gridpath2

GridPath is a Python library for calculating grid-based paths and intersection points between two coordinates. It's particularly useful for applications requiring precise path tracking on a grid system, such as robotics, game development, or computer graphics.

Features

  • Calculate grid-aligned paths between any two points
  • Determine exact intersection points with grid lines
  • Support for horizontal, vertical, and diagonal paths
  • Handle special cases like same-point paths and 45-degree angles
  • Return both grid points and precise intersection coordinates

Installation

pip install gridpath2

Usage

Basic usage example:

from gridpath2 import grid

# Calculate path between two points
result = grid(x1=1.5, y1=2.3, x2=4.7, y2=6.8)

# Access the results
grid_points = result["grid"]      # List of grid points traversed
intersections = result["intersect"] # List of exact intersection points

The function returns a dictionary containing:

  • grid: List of grid points the path traverses through
  • intersect: List of exact coordinates where the path intersects with grid lines

Example Scenarios

  1. Horizontal path:
path = grid(1.5, 2.0, 4.5, 2.0)
# Returns path along y=2
  1. Vertical path:
path = grid(2.0, 1.5, 2.0, 4.5)
# Returns path along x=2
  1. Diagonal path (45 degrees):
path = grid(1.0, 1.0, 3.0, 3.0)
# Returns diagonal path with slope=1
  1. General case:
path = grid(1.5, 2.3, 4.7, 6.8)
# Returns optimal grid path with precise intersections

Function Details

def grid(x1: float, y1: float, x2: float, y2: float) -> dict:
    """Calculate grid path and intersection points between two coordinates.

    Args:
        x1, y1: Starting point coordinates
        x2, y2: Ending point coordinates

    Returns:
        dict: Dictionary containing:
            - "grid": List of grid points [[x1, y1], [x2, y2], ...]
            - "intersect": List of intersection points [[x1, y1], [x2, y2], ...]
    """

Technical Details

The library handles several special cases:

  • Same point paths
  • Horizontal lines
  • Vertical lines
  • 45-degree diagonal lines
  • General cases with arbitrary slopes

For general cases, the algorithm:

  1. Calculates the slope between points
  2. Determines the next grid intersection based on slope direction
  3. Tracks both grid points and exact intersections
  4. Handles positive and negative slopes differently
  5. Provides precise intersection coordinates

Use Cases

  • Robot path planning
  • Game development (grid-based movement)
  • Computer graphics (line rasterization)
  • Scientific visualization
  • CAD applications

Requirements

  • Python 3.6+

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gridpath2-0.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gridpath2-0.1.2-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file gridpath2-0.1.2.tar.gz.

File metadata

  • Download URL: gridpath2-0.1.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for gridpath2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b0bd26bbd82e3c4fc7d859b4a3c5ff2577c74d56ccda19f6b81943613b59037b
MD5 b801bba7982a2f962a432e33dbd0a36d
BLAKE2b-256 4b758ab5ee0a7e141288eba2aa4bc0e63bb93659fc9adb34ce587c31230639ff

See more details on using hashes here.

File details

Details for the file gridpath2-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: gridpath2-0.1.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for gridpath2-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4a068184f85ff4717548a5d7cdf91ae3a86d69f927b6de0009c2ce2730bc60b6
MD5 285a3119639be258156f23e2d91455fa
BLAKE2b-256 f7ae6f88e61d02cf0e026d28f2c11bba393e0b623c9e7c5561f506fcc748d5f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page