SharpPlot Tutorials > Chart Samples > Response surfaces

## Response surfaces

The response surface is generally used with computed data to show a mathematical function of two variables. It may be combined with other 3D charts (typically the cloud chart) to show a theoretical fit in addition to the raw data plotted in 3 dimensions.

### A Simple Mesh Surface

The data is an array of arrays of nodes in the surface, which must be strictly rectangular. Each inner array is drawn parallel to the X-axis, working from front to back.

```mesh = new int[][]{new int[]{8,7,6,5,4,3},new int[]{12,11,10,9,8,7},new int[]{16,15,
14,13,12,11}};

sp.SetMargins(48,12,24,0);
sp.SetMarkers(Marker.Node);

sp.DrawResponsePlot(mesh);
```

### Mesh with Given X and Y Co-ordinates

This has the same arrays for the mesh, but the nodes are placed explicitly in both X and Y directions, so the effect is to stretch the surface.

```mesh = new int[][]{new int[]{8,7,6,5,4,3},new int[]{12,11,10,9,8,7},new int[]{16,15,
14,13,12,11}};
xvalues = new int[] {8,10,16,20,26,48};
yvalues = new int[] {8,12,20};

sp.SetMargins(48,12,24,0);
sp.SetMarkers(Marker.Ball);

sp.DrawResponsePlot(mesh,xvalues,yvalues);
```

### Tiling Two Surfaces

Tiled surfaces are most effectively drawn with semi-transparent fill styles, to allow the axes and any data to show through.

```mesh = new int[][]{new int[]{8,7,6,5,4,3},new int[]{12,11,10,9,8,7},new int[]{16,15,
14,13,12,11}};

sp.SetMargins(48,12,24,0);
sp.Heading = "Tiled Surface with Contours";
ResponsePlotStyles.TiledSurface|ResponsePlotStyles.Contours;
sp.SetFillStyles(FillStyle.Opacity42);

sp.SetContourStyle(Color.Navy,LineStyle.Dash,1.5);

sp.DrawResponsePlot(mesh);
```

This example shows two intersecting planes, each drawn with 30% opacity.

If the mesh genuinely represents ‘altitude’ it can be shaded to represent the range of the Z-axis.

```terrain = new int[][]{new int[]{50,49,50,49,48,50,49,50,49,47,45,45,43,40,40,36,35,
33,34,31,30,32,35,36,38,39,42,42,42,45,49,49,50},new int[]{51,51,49,49,47,
49,48,49,50,46,47,44,43,43,41,41,39,36,33,32,30,32,34,36,38,40,42,44,41,43,
48,49,52},new int[]{54,49,48,49,49,49,47,47,49,49,48,44,42,44,44,44,41,37,
34,34,32,33,33,37,40,41,44,42,42,42,44,47,52},new int[]{57,51,51,48,47,48,
48,51,51,51,49,47,43,43,43,44,43,37,35,34,34,34,35,37,42,41,42,42,44,46,46,
48,51},new int[]{57,54,51,48,47,51,52,52,53,52,49,46,44,45,46,43,42,41,37,
36,36,36,39,40,41,42,42,44,45,47,48,48,49},new int[]{56,55,54,49,46,48,52,
54,55,51,47,46,43,43,45,44,42,40,41,40,37,41,41,43,44,45,42,43,45,45,47,46,
49},new int[]{55,54,54,49,44,48,50,53,54,49,46,44,42,41,43,43,44,42,43,39,
38,43,45,47,49,46,44,46,45,45,46,47,47},new int[]{53,54,53,47,47,47,50,51,
52,50,47,44,43,44,41,44,40,41,41,41,42,44,49,50,51,51,46,45,45,45,46,47,
48},new int[]{52,50,50,49,46,49,49,51,52,49,46,45,43,44,42,41,40,39,40,43,
46,49,51,54,55,52,49,49,47,46,46,47,49},new int[]{53,51,53,50,49,49,51,54,
53,48,46,45,43,42,41,40,39,40,39,41,45,46,49,52,56,54,52,51,51,50,49,49,
52},new int[]{52,53,55,52,52,52,53,54,55,48,44,42,42,42,39,37,37,38,40,41,
44,45,48,52,55,56,55,54,52,52,52,54,56},new int[]{56,55,56,55,57,56,57,55,
55,48,43,43,40,40,38,38,38,39,43,44,45,49,49,53,55,55,54,52,52,53,55,58,
58},new int[]{58,57,57,61,62,59,58,54,52,47,44,42,40,39,40,39,36,40,43,46,
48,51,52,54,54,55,53,54,53,54,58,60,60},new int[]{62,60,59,62,61,59,58,53,
49,48,46,42,37,36,35,37,35,39,42,46,48,50,52,52,56,55,54,51,52,53,58,59,
61},new int[]{66,65,61,61,60,58,57,53,49,48,47,41,36,34,33,32,33,37,39,42,
46,48,51,53,54,55,54,54,51,53,56,59,61},new int[]{66,65,64,63,61,59,57,54,
49,46,46,39,36,34,33,30,30,32,34,39,42,46,49,51,53,55,53,54,54,53,57,57,
59},new int[]{68,67,63,64,64,60,58,54,51,49,43,38,34,33,30,28,27,31,31,35,
40,41,45,48,51,51,54,54,54,55,58,58,59},new int[]{65,62,62,64,63,59,53,53,
49,46,42,40,36,32,31,28,24,29,33,36,39,41,44,47,48,49,51,52,53,53,55,57,
57},new int[]{61,63,63,62,60,56,52,49,48,45,44,38,35,33,31,27,24,28,33,36,
37,40,43,44,47,47,50,49,50,52,51,54,55},new int[]{60,58,61,57,55,53,52,48,
49,47,44,39,34,33,31,26,25,29,31,33,34,37,40,44,49,47,49,50,49,50,49,52,
51},new int[]{57,56,57,53,51,51,49,49,49,44,43,37,34,30,28,26,25,30,32,33,
32,34,37,41,47,48,49,48,47,47,49,49,48},new int[]{58,55,55,53,49,48,46,45,
45,42,39,36,36,35,32,29,27,30,31,34,35,37,37,41,46,48,46,44,44,47,49,48,
50},new int[]{56,55,52,49,45,44,43,43,44,40,36,38,37,36,34,30,28,28,30,32,
37,38,39,43,46,43,42,44,43,46,47,48,49},new int[]{52,49,49,45,42,44,41,43,
42,39,37,36,36,35,34,30,30,32,30,35,37,36,38,39,42,42,43,41,41,42,44,47,
48},new int[]{48,47,45,43,40,41,41,41,39,38,36,34,35,34,35,33,30,31,33,34,
37,35,36,36,39,40,41,40,39,40,41,42,46},new int[]{48,45,43,43,40,40,40,40,
39,38,38,36,36,35,33,34,32,32,34,34,35,36,36,36,39,40,42,40,39,42,43,44,
47},new int[]{48,43,42,40,39,40,38,38,38,37,38,38,37,35,33,35,35,36,36,35,
34,33,35,37,39,42,43,44,43,43,43,46,49},new int[]{44,45,43,40,40,38,40,37,
36,35,37,39,39,36,34,34,35,35,36,33,35,35,38,40,41,40,41,42,43,44,44,47,
50},new int[]{43,43,44,42,39,40,40,37,35,34,36,38,38,39,37,36,34,34,34,33,
33,37,39,40,41,42,41,42,44,44,46,49,52},new int[]{46,44,45,43,41,41,38,37,
36,37,36,37,35,36,35,35,34,34,35,34,37,38,37,40,41,40,41,41,40,43,47,51,
52},new int[]{47,44,44,44,44,42,38,36,36,37,36,34,35,36,35,34,34,34,34,35,
37,38,38,39,40,42,41,39,38,42,48,49,52},new int[]{48,47,47,43,42,40,40,38,
39,37,36,36,36,34,35,35,34,34,35,37,35,37,35,35,37,38,38,37,36,39,46,47,
50},new int[]{50,50,47,45,42,44,43,40,39,40,38,36,36,36,35,35,37,35,37,35,
35,36,36,33,33,36,36,35,36,37,41,47,50}};

sp.SetMargins(48,12,24,0);
sp.XAxisStyle = XAxisStyles.PlainAxis;
sp.YAxisStyle = YAxisStyles.PlainAxis;

sp.SetFillStyles(FillStyle.Opacity66);
sp.SetColors(Color.ForestGreen);

sp.DrawResponsePlot(terrain);
```

This works very well with this style of generated fractal landscape.

### Summary

The response plot can be a very good way to visualise a computed surface in 3 dimensions.