Skip to content

BobLd/Nzy3d

Repository files navigation

Nzy3d

  • Updated net6.0 version of nzy3d-api
  • Uses OpenTK 4.6.7 and the more recent WinForms GLControl
  • Perspective mode bug fixed
  • Available in Winforms and native WPF

How to

Samples

See Nzy3d.WinformsDemo and the ChartsHelper for Winforms examples

Mapper surface

// Create the chart
Chart.Chart chart = new Chart.Chart(renderer3D, Quality.Nicest);
chart.View.Maximized = false;
chart.View.CameraMode = CameraMode.PERSPECTIVE;
chart.View.IncludingTextLabels = true;

// Create a range for the graph generation
var range = new Maths.Range(-150, 150);
const int steps = 50;

// Build a nice surface to display with cool alpha colors 
// (alpha 0.8 for surface color and 0.5 for wireframe)
var surface = Plot3D.Builder.Builder.BuildOrthonomal(new OrthonormalGrid(range, steps, range, steps), new MyMapper());
surface.ColorMapper = new ColorMapper(new ColorMapRainbow(), surface.Bounds.ZMin, surface.Bounds.ZMax, new Color(1, 1, 1, 0.8));
surface.FaceDisplayed = true;
surface.WireframeDisplayed = true;
surface.WireframeColor = Color.CYAN;
surface.WireframeColor.Mul(new Color(1, 1, 1, 0.5));

// Add surface to chart
chart.Scene.Graph.Add(surface);

surface_ripples

Delaunay surface

// Create data
const int size = 100;
List<Coord3d> coords = new List<Coord3d>(size);
float x, y, z;
var r = new Random(0);

for (int i = 0; i < size; i++)
{
	x = r.NextSingle() - 0.5f;
	y = r.NextSingle() - 0.5f;
	z = r.NextSingle() - 0.5f;
	coords.Add(new Coord3d(x, y, z));
}

// Create chart
Chart.Chart chart = new Chart.Chart(renderer3D, Quality.Nicest);
chart.View.Maximized = false;
chart.View.CameraMode = CameraMode.PERSPECTIVE;
chart.View.IncludingTextLabels = true;

// Create surface
var surface = Plot3D.Builder.Builder.BuildDelaunay(coords);
surface.ColorMapper = new ColorMapper(new ColorMapRainbow(), surface.Bounds.ZMin, surface.Bounds.ZMax, new Color(1, 1, 1, 0.8));
surface.FaceDisplayed = true;
surface.WireframeDisplayed = true;
surface.WireframeColor = Color.CYAN;
surface.WireframeColor.Mul(new Color(1, 1, 1, 0.5));

// Add surface to chart
chart.Scene.Graph.Add(surface);

Scatter graph

scatter_1million

// Create data
var points = new Coord3d[size];
var colors = new Color[size];

float x, y, z;
const float a = 0.25f;

var r = new Random(0);
for (int i = 0; i < size; i++)
{
	x = r.NextSingle() - 0.5f;
	y = r.NextSingle() - 0.5f;
	z = r.NextSingle() - 0.5f;
	points[i] = new Coord3d(x, y, z);
	colors[i] = new Color(x, y, z, a);
}

// Create chart
Chart.Chart chart = new Chart.Chart(renderer3D, Quality.Nicest);
chart.View.Maximized = false;
chart.View.CameraMode = CameraMode.PERSPECTIVE;
chart.View.IncludingTextLabels = true;

// Create scatter
var scatter = new Scatter(points, colors);

// Add surface to chart
chart.Scene.Graph.Add(scatter);

References