TeeChart显示三维的图形,使用Surface

绘制一个球

根据公式x^2+y^2+z^2=R^2;

令x=RsinAcosB  y=RcosAcosB z=RsinB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Styles;
using System.Drawing.Drawing2D;
using Steema.TeeChart.Tools; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private TChart tChart1 = new TChart();
private Surface surfaceSeries1 = new Surface();
private GridBand gridBand = new GridBand();
private Surface surfaceSeries2 = new Surface();
public Form1()
{
InitializeComponent();
Init();
} private void Init()
{
tChart1.Series.Add(surfaceSeries1);
tChart1.Series.Add(surfaceSeries2);
tChart1.Dock = DockStyle.Fill; this.tChart1.Aspect.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
this.tChart1.Aspect.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; this.tChart1.Axes.Depth.Visible = true;
this.tChart1.Axes.Depth.Labels.ValueFormat = "0.#";
this.tChart1.Axes.Depth.Increment = 0.2;
this.tChart1.Axes.Bottom.Labels.ValueFormat = "0.#";
this.tChart1.Axes.Bottom.Increment = 0.1; this.tChart1.Aspect.Chart3DPercent = ;
this.tChart1.Aspect.Orthogonal = false;
this.tChart1.Aspect.Perspective = ;
this.tChart1.Aspect.Rotation = ;
this.tChart1.Aspect.Elevation = ;
this.tChart1.Aspect.Zoom = ; this.tChart1.Walls.Bottom.Pen.Visible = false;
this.tChart1.Walls.Bottom.Size = ; this.tChart1.Walls.Left.Pen.Visible = false;
this.tChart1.Walls.Left.Size = ;
this.tChart1.Panel.Brush.Color = System.Drawing.Color.FromArgb(((System.Byte)()), ((System.Byte)()), ((System.Byte)()), ((System.Byte)())); Controls.Add(tChart1); InitSurface(surfaceSeries1, Color.Red); InitSurface(surfaceSeries2, Color.Blue); double r = ;
double z = ; List<double> arrayX = new List<double>();
List<double> arrayY = new List<double>();
List<double> arrayZ = new List<double>(); List<double> arrayX1 = new List<double>();
List<double> arrayY1 = new List<double>();
List<double> arrayZ1 = new List<double>(); tChart1.AutoRepaint = false;
try
{
for (double x = -r; x <= r; x += 0.1)
{
for (double y = -r; y <= r; y += 0.1)
{
z = r * r - x * x - y * y;
if (z >= )
{
z = Math.Sqrt(z);
arrayX.Add(x);
arrayY.Add(y);
arrayZ.Add(-z);
}
}
} for (double x = -r; x <= r; x += 0.1)
{
for (double y = -r; y <= r; y += 0.1)
{
z = r * r - x * x - y * y;
if (z >= )
{
z = Math.Sqrt(z);
arrayX1.Add(x);
arrayY1.Add(y);
arrayZ1.Add(z);
}
}
}
surfaceSeries1.Add(arrayX.ToArray(), arrayZ.ToArray(), arrayY.ToArray());//特别需要注意的是,z在中间
surfaceSeries2.Add(arrayX1.ToArray(), arrayZ1.ToArray(), arrayY1.ToArray());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
tChart1.AutoRepaint = true;
tChart1.Refresh();
} private void InitSurface(Surface s, Color color)
{
s.Pen.Color = color;
s.Marks.Symbol.Shadow.Height = ;
s.Marks.Symbol.Shadow.Visible = true;
s.Marks.Symbol.Shadow.Width = ;
s.NumXValues = ;
s.NumZValues = ;
s.PaletteMin = ;
s.PaletteStep = ;
s.UseColorRange = false;
s.UsePalette = true; s.IrregularGrid = true;
s.ShowInLegend = false;
s.UseColorRange = false;
s.UsePalette = true;
s.PaletteStyle = Steema.TeeChart.Styles.PaletteStyles.Strong;
s.PaletteSteps = ;
}
}
}

TeeChart显示三维的图形,使用Surface

上一篇:“全栈2019”Java第五十九章:抽象类与抽象方法详解


下一篇:武汉科技大学ACM:1001: 猴子选大王