TeeChart 3D 显示三维的图形,使用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 = 100; this.tChart1.Aspect.Orthogonal = false; this.tChart1.Aspect.Perspective = 50; this.tChart1.Aspect.Rotation = 327; this.tChart1.Aspect.Elevation = 352; this.tChart1.Aspect.Zoom = 70; this.tChart1.Walls.Bottom.Pen.Visible = false; this.tChart1.Walls.Bottom.Size = 5; this.tChart1.Walls.Left.Pen.Visible = false; this.tChart1.Walls.Left.Size = 5; this.tChart1.Panel.Brush.Color = System.Drawing.Color.FromArgb(((System.Byte)(254)), ((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(255))); Controls.Add(tChart1); InitSurface(surfaceSeries1, Color.Red); InitSurface(surfaceSeries2, Color.Blue); double r = 10; double z = 0; 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 >= 0) { 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 >= 0) { 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 = 1; s.Marks.Symbol.Shadow.Visible = true; s.Marks.Symbol.Shadow.Width = 1; s.NumXValues = 25; s.NumZValues = 25; s.PaletteMin = 0; s.PaletteStep = 0; 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 = 10; } } }
作者:Chuck Lu GitHub |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库