Metadata-Version: 2.2
Name: pythetastar
Version: 0.0.1
Summary: Implementation of Theta* algorithm
License: MIT License
        
        Copyright (c) 2025 alek5k
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/alek5k/pythetastar
Project-URL: Bug Reports, https://github.com/alek5k/pythetastar/issues
Project-URL: Source, https://github.com/alek5k/pythetastar
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Provides-Extra: dev
Requires-Dist: check-manifest; extra == "dev"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"

# PyThetaStar
Python implementation of the Theta* algorithm (Daniel, Nash, "Theta star, Any-angle path planning on grids"). This is a modified and simplified single-file adaptation of the implementation [found here.](https://github.com/rhidra/phi_star_2d/blob/master/theta_star.py)

Example of path generated:

![Path generated](https://github.com/alek5k/pythetastar/raw/master/examples/path.png)

Dynamic replanning is allowed by modifying `new_blocked_cells` which is an input to the `theta_star` function.

# Installation
`pip install pythetastar`

# Basic Usage
```python
import numpy as np
from pythetastar import theta_star

grid = np.array([
    [0, 0, 0, 0, 1, 0, 1, 1],
    [1, 1, 0, 1, 1, 0, 1, 1],
    [0, 1, 0, 0, 1, 0, 0, 1],
    [1, 1, 1, 0, 1, 1, 0, 1],
    [1, 1, 1, 0, 1, 0, 1, 1],
    [0, 0, 1, 0, 1, 0, 1, 1],
    [0, 1, 1, 0, 0, 0, 1, 1],
    [0, 1, 0, 1, 1, 0, 0, 0]
])
grid_width, grid_height = grid.shape
start = (0, 0)
goal = (grid_width, grid_height)

result_path, node_set, durations, lengths, paths = theta_star(start, goal, grid)
print(result_path) 
# output: [[0, 0], [1, 2], [5, 4], [6, 4], [8, 8]]
```

Plotting:
```python
import matplotlib.pyplot as plt

xs = [n[0] for n in result_path]
ys = [n[1] for n in result_path]

plt.imshow(grid.T, origin='lower', extent=[0, grid_width, 0, grid_height], cmap='cividis') # Transpose aligns rows (axis 0) with y-axis and columns (axis 1) with x-axis.
plt.grid(color='black', linestyle='-', linewidth=0.5)
plt.xticks(range(grid_width))  
plt.yticks(range(grid_height))
plt.plot(xs, ys, 'r-')
plt.scatter(xs, ys)
plt.show()
```
