zoukankan      html  css  js  c++  java
  • 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 = 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;
            }
        }
    }

  • 相关阅读:
    unity3d连接Sqlite并打包发布Android
    EasyTouch中虚拟摇杆的使用EasyJoystick
    在屏幕拖拽3D物体移动
    LineRenderer组建实现激光效果
    unity3d对象池的使用
    自动寻路方案
    贪吃蛇方案
    unity3d射线控制移动
    文件压缩(读取文件优化)
    [LeetCode] 33. 搜索旋转排序数组 ☆☆☆(二分查找)
  • 原文地址:https://www.cnblogs.com/chucklu/p/4514005.html
Copyright © 2011-2022 走看看