tags:

views:

24

answers:

1

How can I implement this method:

private bool IsRegularPolygon(List<Point> seed)

The Point object is in 2 dimensions, with an X and Y coordinate.

And assuming it is regular, how can I find the length of a side?

Thanks!

A: 

Just think back to high school geometry, and think about what makes a polygon "regular".

Since this wouldn't be much of an answer if that's all I said, I'm going to cut to the chase and point out that it's a polygon where all the interior angles are equal.

So this reduces the problem down to making sure that each angle between three points in the list is the same. So something like:

get the first point, and the two after it
find the angle between them, store it somewhere
get the second point, and the two after it
find the angle between them, make sure it's the same
repeat the last two steps for all the points in the list

Now remembering that if it's regular, all the sides are the same length, so finding the side length is a straightforward distance-between-two-points calculation.

Anon.