How to find the flattest area of a poly surface in rhino?

Given a set of xyz points, I want to find clusters of points that have the smallest variation in the z value. Basically how to find the flattest area of a collection of points.

The question is how flat “flattest area” has to be?
Some other condition is necessary to determine which points will satisfy"flatest area" / “smallest variation” condition.
For example minimum number of points to be included in resulting set or some other condtion…

Lets say you have n values of z-coordinates, stored in and arrazy z, so z[i] is z-coordinate for point[i].
Let m be any number of points, then you ca calculate variance for such set of points.
For different set of m points you will get different value of variance, lowest value means smallers variation.
You can iterate this computation for different m (m => 2 to n ) and you will find for evrey m set of point vith minimum variance. Lowes variance will be = 0 if you have at least 2 points with same z value.
Efficient algorithm can be written if list of points is sorted with ascending value of z coordinate.

I hope that this helps…