How to calculate intersection count in a given polygon within a grid

1.3k Views Asked by At

I have the following problem:

  • I have a given polygon (any shape)
  • I have a grid with given size of grid cells (variable width and height)
  • The grid contains the polygon (various number of cells required)

I know the following inputs:

  • number of grid cells to contain the polygon (rows, columns)
  • the number of required full cells and partial cells (that are fully inside or partially intersected with the polygon)
  • the length of each side of the polygon
  • the angle at each corner (between each side)

I need to calculate how many intersections there are in the polygon.

A few example by pictures (I need to know the number of the gray circles):

enter image description here

enter image description here

If you need more clarification, tell me.

Do you have any hint of what kind of formula could count the number of the intersections?