Algorithm for Smoothing Edges on a 2D Grid Map

I’m working on a 2D grid-based map where each cell represents a specific terrain type (e.g., water, sand, grass). I currently have a functional map with distinct terrain zones, I’m looking to visually enhance it by smoothing out the edges between different terrain types by using triangles. The first image shown is how the grid is originally layed out with no triangles. The second image shown is what I’d want the map to look like with the enhancement.

I want to know how I could get the coordinates that make up each vertex of the triangle


There’s that system called dual grid which was explained by Oskar Stålberg in one of his talks, here’s a small demonstration:

This is a dual grid and these are the rounded corners you want, the corners weren’t made using a smoothing algorithm but rather their own tiles.

image

As you can see, these are all the possible tiles, the one you choose depends on the blocks you want around it, if one is surrounded by the same block type then it’ll be a filled one (first or last), if one side is surrounded by a type and the other is surrounded by another type you would use the 3rd tile and change it’s rotation, similarly, each tile has it’s own case, you can make your life easier by making the tiles made of 2 parts colored white and you change the color depending on the tiles around it. In general, it’s a good algorithm and he used it in his game, Townscaper! Here’s the talk where he mentioned and explained this algorithm (skip to ~5:05).

Thanks for your response but my project specifically involves enhancing a 2D grid-based map by smoothing out the edges between different terrain types using triangles. My main challenge is in calculating the coordinates for the vertices of these triangles to achieve a seamless transition between terrains. The dual grid system, while useful, seems to diverge from this particular need as it relies on predefined tile patterns rather than manipulation of vertex coordinates.

If you were able to isolate the green and sand regions (floodfill perhaps) you could do a psuedo raycast left to right and measure the change in depth which indicates if a triangle should be formed.