{"id":32305447,"url":"https://github.com/molteo-engineering-team/point_in_polygon","last_synced_at":"2025-10-23T06:51:17.017Z","repository":{"id":56842138,"uuid":"353661236","full_name":"molteo-engineering-team/point_in_polygon","owner":"molteo-engineering-team","description":"Check if a Point is inside a polygon representing by a List of Point by using a Ray-Casting algorithm","archived":false,"fork":false,"pushed_at":"2022-01-27T20:15:02.000Z","size":12,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2023-08-20T22:56:10.168Z","etag":null,"topics":["coordinates","dart","flutter","polygon","raycasting"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/point_in_polygon","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/molteo-engineering-team.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-01T10:26:54.000Z","updated_at":"2022-09-19T14:15:35.000Z","dependencies_parsed_at":"2022-09-01T06:32:21.808Z","dependency_job_id":null,"html_url":"https://github.com/molteo-engineering-team/point_in_polygon","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/molteo-engineering-team/point_in_polygon","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molteo-engineering-team%2Fpoint_in_polygon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molteo-engineering-team%2Fpoint_in_polygon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molteo-engineering-team%2Fpoint_in_polygon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molteo-engineering-team%2Fpoint_in_polygon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/molteo-engineering-team","download_url":"https://codeload.github.com/molteo-engineering-team/point_in_polygon/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/molteo-engineering-team%2Fpoint_in_polygon/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280577134,"owners_count":26354072,"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","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["coordinates","dart","flutter","polygon","raycasting"],"created_at":"2025-10-23T06:51:14.552Z","updated_at":"2025-10-23T06:51:17.011Z","avatar_url":"https://github.com/molteo-engineering-team.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# point_in_polygon\n\nSimple package to check if a Point (coordinates) is inside a polygon representing by a list of Point by using a Ray-Casting algorithm.\n\n## Usage\n\n```\nfinal List\u003cPoint\u003e points = \u003cPoint\u003e[\n  Point(y: 42.412328554181684, x: -71.61572554715048),\n  Point(y: 42.382918132678284, x: -71.63254836209188),\n  Point(y: 42.36617846481582, x: -71.5951261819161),\n  Point(y: 42.39306121437432, x: -71.5680036843575),\n];\n\nfinal Point point = Point(x: -71.60473921902548, y: 42.38951132221119);\nPoly.isPointInPolygon(point, points)  // true\n\nfinal Point point2 = Point(x: -71.76850417263876, y: 42.38925775080263);\nPoly.isPointInPolygon(point2, points) // false\n```\n## Expanation\n\nRay-Casting algorithm: https://en.wikipedia.org/wiki/Point_in_polygon\n   \nExample case\n  \nLet's  say we have a point and a polygon already, represented by this graph:\n```  \n     |\n    5|\n     |\n     |\n    4|                       * Vertice B (4, 4)\n     |                      / \\\n     |                     /   \\\n    3|     * Point (1, 3) /     \\\n     |                   /       \\\n     |                  /         \\\n    2|                 /           \\\n     |                /             \\\n     |               /               \\\n    1|             * Vertice A (2, 1) \\\n     |              \\                  \\\n     |               \\                  \\\n   -----------------------------------------------------------\n    0|     1     2     3     4     5     6     7     8     9\n``` \nWe will draw a horizontal line from Point and for each line between the vertices, \nwe will figure out whether our horizontal line crosses that line. \nThen if the total number is even (or zero) after doing that calculation for all lines, \nwe know the point is outside, if it is odd it's inside:\n```\n  \n     |\n    5|        * -----------------------------------------\u003e 0 collisions, point is outside\n     |\n     |\n    4|                       * Vertice B (4, 4)\n     |                      / \\\n     |                     /   \\\n    3|     * -----------\u003e /----\u003e\\----------\u003e 2 collisions, even, point is outside\n     |                   /       \\\n     |                  /         \\\n    2|                 /           \\\n     |                /    *-------\u003e\\------\u003e 1 collision, odd, point is inside\n     |               /               \\\n    1|             * Vertice A (2, 1) \\\n     |              \\                  \\\n     |               \\                  \\\n   -----------------------------------------------------------\n    0|     1     2     3     4     5     6     7     8     9\n```\n  \nSo if we don't have the lines, only the corners of the polygon how do we calculate the intersections?\n \n`y = mx + b`\n\nIn this standard linear equation, M is the slope of the line and B is the y-intercept of the line. So if we rearrange it to solve for an X value (as we want to find the X value at which our horizontal line from our point would touch the edge, and whether that value is \u003e the real X), we can insert our point Y value as Y and get our result if we have M and B for the line between two vertices.\n  \nIn our example:\n```\n     |\n    5|\n     |\n     |\n    4|                       * Vertice B (4, 4)\n     |                      / \\\n     |                     /   \\\n    3|     * Point (1, 3) /     \\\n     |                   /       \\\n     |                  /         \\\n    2|                 /           \\\n     |                /             \\\n     |               /               \\\n    1|             * Vertice A (2, 1) \\\n     |              \\                  \\\n     |               \\                  \\\n   -----------------------------------------------------------\n    0|     1     2     3     4     5     6     7     8     9\n```  \nM is 1.5:\n```\nm = (aY - bY) / (aX - bX) \nm = ( 1 - 4 ) / ( 2 - 4 )\nm = 1,5\n```\nB is -2:\n```\nb = ((aX * -1) * m) + aY\nb = (( 2 * -1) * 1.5) + 1\nb = -2\n```\n\nTherefore our intercept point is 3.33:\n```\nx = (pY - b) / m\nx = (3 - -2) / 1.5\nx = 3,33\n```\n3.33 is \u003e our point's X val of 1, so this time the ray intercepts the line. \nWe would do this calculation for all the other edges, and in our example we would have 2 intercepts, so Point is outside the polygon.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolteo-engineering-team%2Fpoint_in_polygon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmolteo-engineering-team%2Fpoint_in_polygon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolteo-engineering-team%2Fpoint_in_polygon/lists"}