■ Surface 클래스를 사용해 3D 원통을 만드는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "Surface 클래스 : 3D 원통 만들기"; this.tChart.Aspect.View3D = true; this.tChart.Aspect.Orthogonal = false; this.tChart.Aspect.Chart3DPercent = 100; this.tChart.Aspect.Zoom = 80; this.tChart.Aspect.Rotation = 320; this.tChart.Aspect.Elevation = 350; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Walls.Visible = false; this.tChart.Axes.Visible = false; this.tChart.Legend.Visible = false; Surface topSurface = new Surface(this.tChart.Chart); topSurface.IrregularGrid = true; topSurface.XValues.Order = ValueListOrder.None; topSurface.YValues.Order = ValueListOrder.None; Surface bottomSurface = new Surface(this.tChart.Chart); bottomSurface.IrregularGrid = true; bottomSurface.XValues.Order = ValueListOrder.None; bottomSurface.YValues.Order = ValueListOrder.None; int arcCount = 50; // 원호 카운트 int zCount = 20; // 원통 길이 Random random = new Random(); double radian180 = GetRadianAngle(180); for(int z = 0; z < zCount; z++) { for(int i = 0; i < arcCount; i++) { double alpha = GetRadianAngle(i * 359 / arcCount); double x = Math.Cos(alpha); double y = Math.Sin(alpha); Color color = Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)); if(alpha < radian180) { topSurface.Add(x, y, z, "", color); } else { bottomSurface.Add(x, y, z, "", color); } } Color color1 = Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)); Color color2 = Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)); bottomSurface.Add(topSurface.XValues.Maximum, Math.Sin(Math.Acos(topSurface.XValues.Maximum)), z, "", color1); bottomSurface.Add(topSurface.XValues.Minimum, Math.Sin(Math.Acos(topSurface.XValues.Minimum)), z, "", color2); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 라디안 각도 구하기 - GetRadianAngle(angle) /// <summary> /// 라디안 각도 구하기 /// </summary> /// <param name="angle">각도</param> /// <returns>라디안 각도</returns> private double GetRadianAngle(double angle) { return angle * (Math.PI / 180d); } #endregion } } |