Question: Would like an algorithm in Python or just code in Python for : Goal: Given an ordered list of points which represent a polygon, return
Would like an algorithm in Python or just code in Python for :
Goal:
Given an ordered list of points which represent a polygon, return the number of points with integer (x, y) coordinates enclosed by the polygon.
Problem:
Provide a RESTful service which accepts as a POST of JSON an ordered list of points represented as (x, y) coordinates. The points define the perimeter of a polygon.
Return the number of points with integer (x, y) coordinates which are fully enclosed by the polygon. Points on the polygon itself are not included in the count the points to be included in the count must be wholly within the area bounded by the polygon.
For example, assuming all points in the grid below are integers, the result would be 13, as points on the polygon itself are not included.
The grid is at maximum 19x19. You can assume all points on the polygon are positive integers between 0 and 18 inclusive.
Example input:
{ inList : [{ x : 2,y : 1 } ,
{ x : 2,y : 4 } ,
{ x : 8,y : 4 },
{ x : 11, y : 1 }
] }
Example output:
{ count : 13 }
Erroneous input (e.g. malformed JSON) should be handled gracefully.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
