How does PolygonGeometry generate the 'values' attribute?

I currently have an interactive polygon maker on my map. After the user marks lat/long coordinates on the map, the PolygonGeometry class generates a polygon with those lat/long coordinates as its vertices.

I am trying to use Geometry.computeNumberOfVertices(geometry) to figure out how many vertices the user generated polygon has. However, it returns ridiculous numbers (like 97, 35, 12, etc.) for simple polygons like triangles and squares. I stepped into the method, computeNumberOfVertices(), and saw that the numOfVertices = numOfValues/componentsPerAttribute (values being a member in GeometryAttribute). However, even when I hardcoded 9 values in the values array with 3 components per attribute (like the first example here: http://cesium.agi.com/Cesium/Build/Documentation/GeometryAttribute.html?classFilter=attr&show=all), it still gives me 35 for the number of vertices because there are 105 values (according to the debugger).

My question is, how does the values array, in GeometryAttribute, get generated when it is not explicitly defined? How come this array length is ~100 when I am drawing a triangle or square with PolygonGeometry?

Thank you in advance,
Lydia

Hi Lydia,

The reason there are so many points generated is because polygons curve to surface of the earth (represented as a WGS84 ellipsoid, not over terrain). If we required the polygon vertices to be co-planar, then we would only use the vertices provided. To generate the points of the geometry, we project the points onto a plane, triangulate the polygon and then further subdivide those triangles to fit the surface of the ellipsoid. How many triangles are generated is configurable. Take a look at the granularity parameter to PolygonGeometry. A higher granularity generates less triangles, but it will not fit the surface of the ellipsoid well. A lower granularity will generate more triangles and fit the ellipsoid better (and look smoother).

Regards,

Dan