@Jacky, yes, it will work for any shape of polygon.
I’m not sure that it is possible to use a side library in the Cesium Sandcastle.
But you can use Turf playground to see how it works.
Example for Turf playground:
const map = L.map("map").setView([42.32481709325035, -72.37353086471558], 20);
L.tileLayer('https://stamen-tiles.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
const polygon = turf.polygon([
[
[-72.37353086471558, 42.32481709325035],
[-72.3738956451416, 42.324594989789134],
[-72.3735523223877, 42.324436343979656],
[-72.37387418746948, 42.32430942704402],
[-72.37363815307616, 42.32405559240466],
[-72.37391710281372, 42.32388108049599],
[-72.37363815307616, 42.32367483852534],
[-72.37352013587952, 42.32375416244021],
[-72.37370252609253, 42.32385728338004],
[-72.37343430519104, 42.32408732179058],
[-72.37361669540404, 42.32429356240905],
[-72.37331628799438, 42.324428411678674],
[-72.373605966568, 42.3246108543481],
[-72.37338066101074, 42.32473777067564],
[-72.37353086471558, 42.32481709325035]
]
]);
L.geoJson(polygon).addTo(map);
// Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
// BBox - bbox extent in minX, minY, maxX, maxY order
// http://turfjs.org/docs/#bbox
const bbox = turf.bbox(polygon);
const cellSideMeter = 1.0;
const options = {
units: 'meters',
mask: polygon
};
// Creates a Point grid from a bounding box, FeatureCollection or Feature.
// FeatureCollection <Point> - grid of points
// http://turfjs.org/docs/#pointGrid
const pointGrid = turf.pointGrid(bbox, cellSideMeter, options);
const pointGridCoordinates = pointGrid.features.map(f => f.geometry.coordinates);
console.log(pointGridCoordinates);
After these calculations you may copy resulted pointGrid coordinates from a console to Cesium Sandcastle code, like here