資源簡介
用GDI+設計B樣條實現代碼,對于給定的多個控制點,生成平滑曲線,

代碼片段和文件信息
using?System;
using?System.Drawing;
using?System.Collections;
using?System.ComponentModel;
using?System.Windows.Forms;
using?System.Drawing.Imaging?;
using?System.Drawing.Drawing2D?;
using?System.IO;
namespace?WindowsApplication1
{
????public?partial?class?Form1?:?Form
????{
????????public?double[]?splinex?=?new?double[1001];
????????public?double[]?spliney?=?new?double[1001];
????????public?point[]?pt?=?new?point[6];
????????public?int?no_of_points?=?0;
????????int[]?a1?=?new?int[12];
????????int[]?b1?=?new?int[12];
???????
?????????public?Form1()
????????{
????????????InitializeComponent();
????????????
????????}
????????public?struct?point
????????{
????????????public?int?x;
????????????public?int?y;
????????????public?void?setxy(int?i?int?j)
????????????{
????????????????x?=?i;
????????????????y?=?j;
????????????}
????????}??
????????//?Prints?a?dot?at?the?place?whrere?the?mouseup?event?occurs?
????????private?void?pictureBox1_MouseUp(object?sender?MouseEventArgs?e)
????????{
????????????Graphics?g?=?pictureBox1.CreateGraphics();
????????????Color?cl=Color.Black;
????????????g.DrawLine?(new?Pen(cl?2)?e.X?e.Y?e.X+1???e.Y+1??);
????????}
????????//?At?each?mousedown?event?the?the?no?of?points?is?calculated?if?the?value?is?more?than?3
????????//then?the?curve?is?drawn
????????private?void?pictureBox1_MouseDown(object?sender?MouseEventArgs?e)
????????{
???????????? if?(no_of_points?>?3)
{
pt[0]?=?pt[1];pt[1]?=?pt[2];pt[2]?=?pt[3];
????????????????????pt[3].setxy(e.X?e.Y);
????????????????????double?temp?=?Math.Sqrt(Math.Pow(pt[2].x?-?pt[1].x?2F)?+?Math.Pow(pt[2].y?-?pt[1].y?2F));
int?interpol?=?System.Convert.ToInt32(temp);
bsp(pt[0]pt[1]pt[2]pt[3]interpol);
int?i;?
????????????????????int?width=2;
????????????????????Graphics?g?=?pictureBox1.CreateGraphics();
????????????????????Color?cl=Color.Blue;
????????????????????int?xy;
????????????????????//?the?lines?are?drawn
for?(i?=?0;?i?<=?interpol?-?1;?i++)
{
?x=System.Convert.ToInt32(splinex[i]);
?????????????????????y=System.Convert.ToInt32(spliney[i]);????????????????????
?????????????????????g.DrawLine(??new?Pen(cl?width)??x?-?1?y?x?+?1?y);
??????????????????????g.DrawLine(new?Pen(cl?width)?x?y?-?1?x?y?+?1);
???????????????????????????????
????????????????????}
}
else
{
pt[no_of_points].setxy(e.X?e.Y);
}
no_of_points?=?no_of_points?+?1; ?
?
????????}
?????????
????????//?calculating?the?values?using?the?algorithm?
????????public?void?bsp(point?p1?point?p2?point?p3?point?p4?int?divisions)
????????{
????????????double[]?a?=?new?double[5];
????????????double[]?b?=?new?double[5];
????????????a[0]?=?(-p1.x?+?3?*?p2.x?-?3?*?p3.x?+?p4.x)?/?6.0;
????????????a[1]?=?(3?*?p1.x?-?6?*?p2.x?+?3?*?p3.x)?/?6.0;
????????????a[2]?=?(-3?*?p1.x?+?3?*?p3.x)?/?6.0;
????????????a[3]?=?(p1.x?+?4?*?p2.x?+?p3.x)?/?6.0
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????946??2006-12-07?19:45??WindowsApplication1\WindowsApplication1.sln
?????文件????????8704??2006-12-07?19:45??WindowsApplication1\WindowsApplication1.suo
?????目錄???????????0??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\
?????目錄???????????0??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\bin\
?????目錄???????????0??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\bin\Debug\
?????文件???????20480??2006-12-08?00:40??WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.exe
?????文件????????5632??2005-09-23?06:56??WindowsApplication1\WindowsApplication1\bin\Debug\WindowsApplication1.vshost.exe
?????文件????????3678??2006-12-08?00:40??WindowsApplication1\WindowsApplication1\Form1.cs
?????文件????????2536??2006-12-08?00:40??WindowsApplication1\WindowsApplication1\Form1.Designer.cs
?????文件????????5814??2006-12-08?00:40??WindowsApplication1\WindowsApplication1\Form1.resx
?????文件?????????486??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Program.cs
?????目錄???????????0??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\
?????文件????????1294??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\AssemblyInfo.cs
?????文件????????2865??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\Resources.Designer.cs
?????文件????????5612??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\Resources.resx
?????文件????????1102??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\Settings.Designer.cs
?????文件?????????249??2006-12-07?19:44??WindowsApplication1\WindowsApplication1\Properties\Settings.settings
?????文件????????3245??2006-12-07?19:50??WindowsApplication1\WindowsApplication1\WindowsApplication1.csproj
- 上一篇:dns域名解析簡單實現
- 下一篇:Opencv 目標檢測和識別
評論
共有 條評論