码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-19 12:50:50      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:

绘制一个球

根据公式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;
        }
    }
}

技术分享

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

标签:

原文地址:http://www.cnblogs.com/chucklu/p/4514005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!