{"id":19449974,"url":"https://github.com/cantaro86/cut-pyramid-polygon","last_synced_at":"2025-07-29T02:35:29.477Z","repository":{"id":134626334,"uuid":"201116907","full_name":"cantaro86/Cut-Pyramid-Polygon","owner":"cantaro86","description":"Determining the cut of any given polygon and a pyramid","archived":false,"fork":false,"pushed_at":"2019-08-07T19:44:25.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-07T23:40:03.447Z","etag":null,"topics":["cpp","geometry","polygon-clipping","sutherland-hodgman"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cantaro86.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-08-07T19:42:47.000Z","updated_at":"2019-09-06T14:12:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"7a55305b-09cc-41c5-a7b8-45943fe94092","html_url":"https://github.com/cantaro86/Cut-Pyramid-Polygon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cantaro86%2FCut-Pyramid-Polygon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cantaro86%2FCut-Pyramid-Polygon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cantaro86%2FCut-Pyramid-Polygon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cantaro86%2FCut-Pyramid-Polygon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cantaro86","download_url":"https://codeload.github.com/cantaro86/Cut-Pyramid-Polygon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240637077,"owners_count":19833001,"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":["cpp","geometry","polygon-clipping","sutherland-hodgman"],"created_at":"2024-11-10T16:34:40.316Z","updated_at":"2025-02-25T09:19:49.840Z","avatar_url":"https://github.com/cantaro86.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Determining the cut of any given polygon and a pyramid \n==========================\n\nThis is a tri-dimensional geometry problem I solved in C++ for an exam.   \nIt uses the **Sutherland–Hodgman** algorithm to find the intersection between two polygons.\n\n\n1)  Problem description\n\nDetermine the cut of any given polygon (2 dimensional) and a pyramid (3 di-\nmensional).\nThe polygon and the base of the pyramid are assumed to have more than 2\nvertexes and are convex.\nThe pyramid is assumed to be a filled solid. If the intersection is empty, then\nreturns the empty polygon. If the polygon is inside the pyramid, then returns\nthe original polygon.\n\n2)  Algorithm\n\nThe algorithm to solve the problem is the following:   \n\n A) Determine the plane containing the polygon A.  \n B) Determine the intersection of the plane with the pyramid. The result is another convex polygon B.  \n C) Determine the intersection between A and B.  \n\n- A  \nIn order to get the plane it is enough to use the function `GetPlane`. Here it is important to have previously checked the quality of the vertexes (they should not be aligned and should form a convex polygon). The algorithm checks also if the points belong to the same plane, however this is not relevant for the use of GetPlane since it only uses the first 3 points.  \nAnother important thing is to select an orientation for the plane, i.e. if we want to look the plane from above or from below (or left or right if it is vertical). This feature is implemented in the function `Plane::Set`. Having an orientation is important when ordering the points clockwise with the function `ordering`.\nThe function `ordering` sorts the points in clockwise order. First it computes the barycenter and the segments connecting it with each points. Then it sorts all the segments using the angle between each segment and a reference segment. The angle is obtained using the arctan function and the properties of the cross and\nscalar products.\n- B  \nThe intersection between the plane and the pyramid is computed by the function `Pyramid::intersect_Pyr_Plane`. It basically computes the line-plane intersection between the plane and each edge of the pyramid.\n- C  \nI decided to compute the intersection between the initial polygon A and the polygon B obtained in step 2, by using the **Sutherland–Hodgman** algorithm.\nThe function `Pyramid::GetAreaInsidePyramid` first considers some particular cases, i.e. when the final output is the empty polygon or a single point polygon, and then implements the Sutherland–Hodgman method. \n\n#### Instructions:\nIn the `testcase.cpp` file the Pyramid and Polygon objects are created. You can add more points if you wish.\nThe output of the program represents the vertexes of the polygon resulting from the intersection.\n\nTo compile the program just run `make` in the shell.\n\n#### Comments:\nThe code is not well written but it works correctly. It uses both C-style vectors and STL vectors. It returns objects by value and not by reference. In a future implementation I suggest to return smart pointers owning the Vector objects. Another improvement is to use the std::map instead of a std::vector in order to keep the elements (Points) ordered. The function `ordering` is not efficient at all.        \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcantaro86%2Fcut-pyramid-polygon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcantaro86%2Fcut-pyramid-polygon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcantaro86%2Fcut-pyramid-polygon/lists"}