{"id":16272319,"url":"https://github.com/perinim/shapedocking","last_synced_at":"2025-04-08T15:47:24.403Z","repository":{"id":194506516,"uuid":"690432212","full_name":"PeriniM/ShapeDocking","owner":"PeriniM","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-08T18:11:34.000Z","size":502,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T12:19:12.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeriniM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-12T07:25:41.000Z","updated_at":"2023-09-13T09:10:54.000Z","dependencies_parsed_at":"2024-11-10T05:32:05.134Z","dependency_job_id":null,"html_url":"https://github.com/PeriniM/ShapeDocking","commit_stats":null,"previous_names":["perinim/shapedocking"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeriniM%2FShapeDocking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeriniM%2FShapeDocking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeriniM%2FShapeDocking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeriniM%2FShapeDocking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeriniM","download_url":"https://codeload.github.com/PeriniM/ShapeDocking/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247875120,"owners_count":21010838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T18:17:16.863Z","updated_at":"2025-04-08T15:47:19.394Z","avatar_url":"https://github.com/PeriniM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shape Docking\n![Good Matching Configurations](images/good_matches.png)\n\n## Installation\n```bash\ngit clone https://github.com/PeriniM/ShapeDocking.git\ncd ShapeDocking\npython -m venv env\nsource env/bin/activate (or ./env/Script/activate)\npip install -r requirements.txt\n```\n\n## Problem Statement\n\nThe challenge is to determine how two distinct polygons can align without overlap. This involves understanding their internal structures, their orientations, and then making informed decisions about their spatial configuration.\n\nWhile several configurations are possible, this project aims to find the most harmonious juxtapositions of the two polygons.\n\n## Solution Strategy\n\n### 1. **Histogram Analysis**:\n\n- **Internal Angles**: The first step is to calculate a histogram for the internal angles of both polygons. This helps understand the inherent structure and orientation of the polygons.\n\n- **Normals**: The next step is to create a histogram for the normals with respect to the edges of each polygon, oriented towards an absolute reference frame (0° pointing to the right, 90° pointing upwards, -90° pointing downwards, etc.). This offers a clear representation of the directional attributes of each polygon's edges.\n\n![Histogram Analysis](images/histograms.png)\n\n### 2. **Heatmap Creation**:\n\nBy calculating the difference between the two histograms of the polygons, two distinct heatmaps are created:\n\n- One for the internal angles\n- One for the normals\n\nThese heatmaps visualize the potential differences and similarities between the two polygons and their possible alignments.\n\n![Heatmap of Differences](images/heatmaps.png)\n\n### 3. **Identifying Minima**:\n\nUsing `skimage`, minima points are identified on the heatmap. These points signify potential areas where the two polygons can align closely, minimizing their differences.\n\n![Heatmap with minima](images/heatmaps_minima.png)\n\n### 4. **Rotation and Alignment**:\n\nFor each minima detected:\n\n- The rotation required to align the two polygons is calculated from the normals' histogram.\n  \n- The second polygon is then rotated counter-clockwise by the determined angle.\n\n- Once rotated, the polygons are then moved such that the midpoints of their corresponding edges are as close as possible.\n\n![All Configurations](images/all_matches.png)\n\n### 5. **Good Matches Configuration**:\n\nThe final step is to determine if there are intersections between the two polygons. If there are no intersections, the configuration is considered a good match.\n\n![Good Matching Configurations](images/good_matches.png)\n\n## Conclusion\n\nThis project provides an innovative method to align two distinct polygons using histogram analysis, heatmap generation, and computational geometry. By integrating multiple techniques, it becomes possible to not just find all feasible configurations, but to discern which of these is the most harmonious.\n\n## Future Work\n\n- **Polygon Generation**: The current implementation of the project uses a fixed set of polygons. In the future, it would be interesting to generate random polygons and test the algorithm on them.\n\n- **Continuous edges**: The current implementation of the project uses discrete edges. In the future, it would be interesting to use continuous edges and test the algorithm on them.\n\n## References\n\n- [A Polygon and Point-Based Approach to Matching Geospatial Features](https://www.mdpi.com/2220-9964/6/12/399)\n\n## Author\n\n- [Marco Perini](https://www.linkedin.com/in/perinim/) - MSc in Mechatronics Engineering, University of Trento\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperinim%2Fshapedocking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperinim%2Fshapedocking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperinim%2Fshapedocking/lists"}