This loop assumes that the geometries are two dimensional, which is not always the case. You need to respect the geometry's stride. Consider:
```js
var stride = geometry.getStride();
for (i = 0, ii = coords.length; i < ii; i += stride) {
  var rotX = coords[i] * cosAngle - coords[i + 1] * sinAngle;
  var rotY = coords[i] * sinAngle + coords[i + 1] * cosAngle;
  // etc.
}
```