Liduo - 3 years ago 160
C Question

# C Algorithm to determine the largest polygon out of a dot matrix

Here's a question which annoyed me through the night.

Given a set of points, say:

``````1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
``````

the largest polygon is a 4x4 square. For this:

``````0 0 1 1 1
0 1 1 1 1
1 1 1 1 1
``````

the largest is the trapezoid, but there will be irregular, and other variations...

How to determine the largest possible? (The largest means the one cannot be enclosed by any other polygon) What kind of algorithm should I use?

Also they need other attributes, like area, perimeter, convex(t/f), and number of invariant rotations...

This is provided in the instruction but I don't really understand what exactly it is about...

Call encoding any 2-dimensional array of size between between 2x2 and 50x50 (both dimensions can be different),
all of whose elements are either 0 or 1.
Call neighbour of a member
`m`
of an encoding any of the at most eight members of the array whose value is 1,
and each of both indexes differs from
`m`
's corresponding index by at most 1. Given a particular encoding, we
inductively determine for all natural numbers
`d`
the set of polygons of depth
`d`
(for this encoding) as follows:

Let a
natural number
`d`
be given, and suppose that for all d0 < d, the set of polygons of depth d0 has been determined.
Change in the encoding all 1's that determine those polygons to 0. Then the set of polygons of depth d is determined
as the set of polygons which can be obtained from that encoding by connecting 1's with some of their neighbours
in such a way that we obtain a maximal polygon (that is, a polygon which is not included in any other polygon
obtained from that encoding by connecting 1's with some of their neighbours).

``````Create some integer B, set it to zero.