<p>For a 3D terrain, you can triangulate using the points projected onto the XY-plane. This is easily implemented in CGAL using the <a href="https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Projection__traits__xy__3.html" rel="nofollow noreferrer">Projection_traits_xy_3</a> class, as in this terrain triangulation <a href="https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Delaunay_Terrain" rel="nofollow noreferrer">example</a>.  </p>

<p>For the fusion of the road triangulation you can use a <a href="https://en.wikipedia.org/wiki/Constrained_Delaunay_triangulation" rel="nofollow noreferrer">constrained Delaunay triangulation</a>. You constrain the road mesh and insert the regular grid points of the terrain mesh to construct the full triangulation. See this <a href="https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Polygon_triangulation" rel="nofollow noreferrer">code</a> for an example of how to use CGAL's constrained Delaunay triangulation.</p>

<p>This should enable you to solve the problem without going into the details of the triangles.
If the result is not good enough, you can always refine the mesh by inserting additional points in problematic triangles.</p>

CC BY-SA 4.0
2018-06-27T07:43:02.357Z
2018-06-27T07:43:02.357Z
Iddo Hanniel
<p>I think the best way to tackle this problem would be to make an algorithm that works on a single triangle at a time.</p>

<p>You'd look at each terrain triangle individually that the road intersected and process it.</p>

<p>Looking at one triangle individually, you would have to chop that triangle into one or more meshes to make it contour to the road.</p>

<p>Here are some of the cases to consider in the image below.  I'm betting there is some triangle slicing algorithm that would be suited to this, and I'm not sure of a name off hand, but the main contribution I'm proposing here is that you deal with triangles individually.</p>

<p><a href="https://i.sstatic.net/qZVx4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qZVx4.png" alt="enter image description here"></a></p>

<p>When cutting the triangle on the x/y plane to make a hole for for the road, you would also want the terrain to take on the z value (height) of the road, for those vertices that touch the road.  This will make the terrain rise up to meet the road.</p>

<p>At this point, you'd have a terrain mesh which did conform to the road but it would be ugly.</p>

<p>Instead of having a nice even looking hill that went up to the road at reasonable slopes, you'd have some triangles that went very sharply up to the road, and others that had a very flat slope.</p>

<p>What you would need to do now is do some kind of "relaxation" algorithm to address this.</p>

<p>Basically, if something is too steep, because there wasn't enough triangle to make the height adjustment, you need to make your whole triangle closer in height to the road and bleed off some of the height adjustment to neighboring triangles.</p>

<p>If something was not steep enough for your liking, because there was a lot of triangle to make a small height adjustment, you may want to break the triangle up into more polygons where it gets closer to the road and have that smaller area handle the change in elevation.</p>

<p>During this second step, when you added a vertex to an edge between two triangles you would also need to adjust the triangle that shares the edge to prevent cracks from showing up in the terrain.</p>

<p>The details are a bit vague, but hopefully the two step approach will help you tackle the problem.</p>

<ol>
<li>Make the terrain mesh adapt to the road, without caring about how it looks.</li>
<li>Refine the terrain mesh to make it appear to meet the road in a more organic man made way.</li>
</ol>

CC BY-SA 3.0
2017-10-17T00:35:59.907Z
2017-10-18T16:36:39.667Z
2017-10-18T16:36:39.667Z
Alan Wolfe
<p>I am experienced with C++ and know more embedded device related stuff but have absolutely no knowledge of computer graphics and its algorithms.</p>

<p>I would like to get a road mesh (based off of a spline) blended seamlessly into a terrain mesh, which is based on a regular grid, like in the picture below. How is this achieved?</p>

<p>Just looked at the CGAL documentation and I cannot even see which problem I am facing and which package to study. Delauney refinement maybe? But I only see a CGAL package for 2D. I'd like to generate a 3D mesh.</p>

<p>The road mesh should be unmodified, the terrain mesh can be altered to form a seamloss mesh.</p>

<p>Can you guide me to the kind of algorithms needed for this?</p>

<p>Kind regards
Max</p>

<p><a href="https://i.sstatic.net/v0EMM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v0EMM.png" alt="enter image description here"></a></p>

<mesh><grid>
Fuse detailed road mesh with regular grid terrain mesh
Max
# Fuse detailed road mesh with regular grid terrain mesh

(Asked by: username_0 on 2017-10-15)

I am experienced with C++ and know more embedded device related stuff but have absolutely no knowledge of computer graphics and its algorithms.

I would like to get a road mesh (based off of a spline) blended seamlessly into a terrain mesh, which is based on a regular grid, like in the picture below. How is this achieved?

Just looked at the CGAL documentation and I cannot even see which problem I am facing and which package to study. Delauney refinement maybe? But I only see a CGAL package for 2D. I'd like to generate a 3D mesh.

The road mesh should be unmodified, the terrain mesh can be altered to form a seamloss mesh.

Can you guide me to the kind of algorithms needed for this?

Kind regards
Max

[![enter image description here](https://i.sstatic.net/v0EMM.png)](https://i.sstatic.net/v0EMM.png)

**Tags:** mesh, grid


---

## 2 answers

### Answer by username_2 on 2017-10-17. Score: 2

I think the best way to tackle this problem would be to make an algorithm that works on a single triangle at a time.

You'd look at each terrain triangle individually that the road intersected and process it.

Looking at one triangle individually, you would have to chop that triangle into one or more meshes to make it contour to the road.

Here are some of the cases to consider in the image below. I'm betting there is some triangle slicing algorithm that would be suited to this, and I'm not sure of a name off hand, but the main contribution I'm proposing here is that you deal with triangles individually.

[![enter image description here](https://i.sstatic.net/qZVx4.png)](https://i.sstatic.net/qZVx4.png)

When cutting the triangle on the x/y plane to make a hole for for the road, you would also want the terrain to take on the z value (height) of the road, for those vertices that touch the road. This will make the terrain rise up to meet the road.

At this point, you'd have a terrain mesh which did conform to the road but it would be ugly.

Instead of having a nice even looking hill that went up to the road at reasonable slopes, you'd have some triangles that went very sharply up to the road, and others that had a very flat slope.

What you would need to do now is do some kind of "relaxation" algorithm to address this.

Basically, if something is too steep, because there wasn't enough triangle to make the height adjustment, you need to make your whole triangle closer in height to the road and bleed off some of the height adjustment to neighboring triangles.

If something was not steep enough for your liking, because there was a lot of triangle to make a small height adjustment, you may want to break the triangle up into more polygons where it gets closer to the road and have that smaller area handle the change in elevation.

During this second step, when you added a vertex to an edge between two triangles you would also need to adjust the triangle that shares the edge to prevent cracks from showing up in the terrain.

The details are a bit vague, but hopefully the two step approach will help you tackle the problem.

1. Make the terrain mesh adapt to the road, without caring about how it looks.
2. Refine the terrain mesh to make it appear to meet the road in a more organic man made way.


---

### Answer by username_1 on 2018-06-27. Score: 0

For a 3D terrain, you can triangulate using the points projected onto the XY-plane. This is easily implemented in CGAL using the [Projection\_traits\_xy\_3](https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Projection__traits__xy__3.html) class, as in this terrain triangulation [example](https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Delaunay_Terrain).

For the fusion of the road triangulation you can use a [constrained Delaunay triangulation](https://en.wikipedia.org/wiki/Constrained_Delaunay_triangulation). You constrain the road mesh and insert the regular grid points of the terrain mesh to construct the full triangulation. See this [code](https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Polygon_triangulation) for an example of how to use CGAL's constrained Delaunay triangulation.

This should enable you to solve the problem without going into the details of the triangles.
If the result is not good enough, you can always refine the mesh by inserting additional points in problematic triangles.


---

