2-D function plots are created by using the Function2D class. This class graphically represents a Function2DGrid object in a variety of ways, depending on the value of the Type property.
The following example shows how to use this class:
Expand source code
The Function2D class
This class produces a 2-D function plot from an underlying Function2DGrid object (stored in the Function property), whose appearance depends on the value of the Type property:
If Type is PlotType.SampledPoints, the points that have been sampled in the Function2DGrid are shown by drawing them using the SampledPointElement symbol.
If Type is PlotType.Tessellation, a Voronoi tessellation of the plot space is performed, based on the points that have been sampled in the Function2DGrid. Each cell is then coloured based on the corresponding sampled point. If the Function2DGrid has been sampled using a regular sampling strategy (rectangular or hexagonal), this is much faster because the shape of the cells is already known.
If Type is PlotType.Raster, a raster image at a fixed resolution (determined by the RasterResolutionX and RasterResolutionY properties) is created by interpolating the values of the Function2DGrid using a bilinear interpolation strategy. This is then scaled to cover the required area in the plot space. If the Function2DGrid has been sampled using an irregular strategy, a Voronoi tessellation is performed and then rasterised, instead.
The constructor for this class requires the Function2DGrid object being plotted as an argument, as well as a continuous invertible coordinate system.
In all cases, the Colouring property is used to determine the colour of each point or Voronoi cell. This should be set to a function accepting a single argument of type double, ranging from 0 to 1 (scaling on the function values is performed automatically by the Function2DGrid class), and returning a Colour corresponding to that value. The static class VectSharp.Gradients has a number of functions that work like this, and there is also an implicit conversion operator defined for GradientStops objects that allow them to be used in this fashion.