■ PolyFitting 클래스의 Coefficient 메소드를 사용해 다항식 계수를 구하는 방법을 보여준다.
▶ 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
using System; using System.Drawing; using System.Text; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Functions; using Steema.TeeChart.Styles; using Steema.TeeChart.Tools; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 패스트 라인 1 시리즈 /// </summary> private FastLine fastLine1; /// <summary> /// 다항식 맞춤 함수 /// </summary> private PolyFitting polyFitting; /// <summary> /// 패스트 라인 2 시리즈 /// </summary> private FastLine fastLine2; /// <summary> /// 커서 도구 /// </summary> private CursorTool cursorTool; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 패스트 라인 1 시리즈를 생성한다. this.fastLine1 = new FastLine(); this.fastLine1.Title = "Data"; this.fastLine1.Color = Color.FromArgb(68, 102, 163); #endregion #region 다항식 맞춤 함수를 생성한다. this.polyFitting = new PolyFitting(); this.polyFitting.PolyDegree = 4; #endregion #region 패스트 라인 2 시리즈를 생성한다. this.fastLine2 = new FastLine(); this.fastLine2.Title = "Poly"; this.fastLine2.Color = Color.FromArgb(243, 156, 53); this.fastLine2.DataSource = this.fastLine1; this.fastLine2.Function = this.polyFitting; #endregion #region 커서 도구를 생성한다. this.cursorTool = new CursorTool(); #endregion #region 티차트를 설정한다. this.tChart.Tools.Add(this.cursorTool); this.tChart.Series.Add(this.fastLine1); this.tChart.Series.Add(this.fastLine2); #endregion Load += Form_Load; this.tChart.MouseMove += tChart_MouseMove; this.tChart.AfterDraw += tChart_AfterDraw; this.fastLine1.FillSampleValues(100); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 폼 로드시 처리하기 - Form_Load(sender, e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_Load(object sender, EventArgs e) { ShowFunction(); } #endregion #region 티차트 마우스 이동시 처리하기 - tChart_MouseMove(sender, e) /// <summary> /// 티차트 마우스 이동시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tChart_MouseMove(object sender, MouseEventArgs e) { double x = this.fastLine2.GetHorizAxis.CalcPosPoint(e.X); double y = this.polyFitting.GetCurveYValue(this.fastLine1, x); this.cursorTool.XValue = x; this.cursorTool.YValue = y; } #endregion #region 티차트 그리기 후 처리하기 - tChart_AfterDraw(sender, graphics) /// <summary> /// 티차트 그리기 후 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics">그래픽스 3D</param> private void tChart_AfterDraw(object sender, Graphics3D graphics) { if(this.cursorTool.XValue > this.tChart.Axes.Bottom.Minimum && this.cursorTool.XValue < this.tChart.Axes.Bottom.Maximum) { graphics.Brush.Color = Color.Red; graphics.Brush.Visible = true; int x = this.cursorTool.GetHorizAxis.CalcPosValue(this.cursorTool.XValue); int y = this.cursorTool.GetVertAxis.CalcPosValue (this.cursorTool.YValue); graphics.Rectangle(x - 5, y + 5, x + 5, y - 5); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 함수 표시하기 - ShowFunction() /// <summary> /// 함수 표시하기 /// </summary> private void ShowFunction() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("y ="); for(int i = 0; i < this.polyFitting.PolyDegree; i++) { stringBuilder.Append(" "); if(this.polyFitting.Coefficient(i) >= 0.0) { if(i > 0) { stringBuilder.Append("+ "); } } stringBuilder.Append(this.polyFitting.Coefficient(i).ToString("0.00##")); if(i > 0) { stringBuilder.Append("*x"); } if(i > 1) { stringBuilder.Append("^" + i.ToString()); } } this.messageLabel.Text = "Function : " + stringBuilder.ToString().Replace("-", "- ").Replace("*", " * ").Replace("^", " ^ "); } #endregion } } |