Y分形的平面微帶天線生成過程
摘要:Call Paint_Line(x,y+L,x-L1*sin(a),y+L+L1*cos(a)) 'Draw Left Diagonal Line。Call Paint_Line(-(y+L),x,-(y+L+L1*cos(a)),x-L1*sin(a)) 'Draw Left Diagonal Line。
Y分形的平面微帶天線生成過程
本文介紹了使用Altium Designer腳本程序生成Y型天線的過程,在窗體中線寬、迭代次數,邊框長度可以直接設置。
Y分形天線用戶界面由一個窗體、1個TImage控件、3個TLable控件、3個TEdit控件、一個TButton控件構成,
窗體步驟如下 :
- 新建一個 VB Script Form文件,保存腳本文件,將文件命名爲Y分形天線設計。
- 將窗體的 Caption屬性改爲“Y分形天線設計”。
- 在窗體中添加 1個TImage控件、3個TLable控件、3個TEdit控件、一個TButton控件。
- 在 TImage控件中加入圖片,將3個TLable控件的Caption分別改爲“邊長(mm):”、“線寬(mm):”、“迭代次數:”。將3個TEdit控件的Text屬性分別改爲“100”、“2”、“4”,將TButton控件的Caption屬性改爲“生成”。
窗體如下圖所示
圖元分析:
Y分形天線的基本結構如 下 所示。基本的圖元由主幹 M、左分支L、右分支R構成,再一次迭代以左分支的終點和右分支的終點上增加一個基本Y型圖元。
Y分形天線 的基本圖元爲 Y型,上下左右四個方向都向前生長Y型的分支,向上Y型每次迭代主幹M都是垂直向上,左、下、右Y型分支和上Y型分支相同,可由上Y型生成之後將座標依次變換一下,得到左、下、右Y型分支,生成的圖像如下圖所示,源碼附後 。
源程序:
PI = 3.1415926
Sub Start_PCBServer()
Call Client.StartServer("PCB")
PcbFileName = "PCB1.PcbDoc"
Set Document = Client.OpenDocument("PCB", PcbFileName)
If Not (Document Is Nothing) Then
'Add this schematic sheet in the newly created PCB project in DXP.
Set Workspace = GetWorkspace
If Not (Workspace Is Nothing) Then
Workspace.DM_FocusedProject.DM_AddSourceDocument(Document.FileName)
End If
Client.ShowDocument(Document)
End If
End Sub
'Draw Line Function
Sub Paint_Line(x1,y1,x2,y2)
Dim Board
Dim Track
Set Board = PCBServer.GetCurrentPCBBoard
Track = PCBServer.PCBObjectFactory(eTrackObject,eNoDimension,eCreate_Default)
Track.X1 = MMsToCoord(CLng(x1)+Board.GetState_XOrigin/10000*0.0254)
Track.Y1 = MMsToCoord(CLng(y1)+Board.GetState_XOrigin/10000*0.0254)
Track.X2 = MMsToCoord(CLng(x2)+Board.GetState_XOrigin/10000*0.0254)
Track.Y2 = MMsToCoord(CLng(y2)+Board.GetState_XOrigin/10000*0.0254)
Track.Layer = eTopLayer
Track.Width = MMsToCoord(Round(Edit2.Text))
Board.AddPCBObject(Track)
Board.LayerIsDisplayed(ALayer) = True
End Sub
'Draw rectangle Function
Sub Paint_Rectangle(x1,y1,x2,y2)
call Paint_Line(x1,y1,x2,y1)
call Paint_Line(x1,y1,x1,y2)
call Paint_Line(x1,y2,x2,y2)
call Paint_Line(x2,y1,x2,y2)
End Sub
Sub Action_Redraw()
Call Client.SendMessage("PCB:Zoom","Action=Redraw", 255, Client.CurrentView)
Call Client.SendMessage("PCB:Zoom","Action=All", 255, Client.CurrentView)
End Sub
'SetState_Origin
Sub Set_Origin()
Set Board = PCBServer.GetCurrentPCBBoard
Board.SetState_YOrigin(80000000)
Board.SetState_XOrigin(80000000)
End Sub
Sub Board_Shape()
Call AddStringParameter("Scope", "All")
RunProcess("PCB:Select")
Call AddStringParameter("Mode", "BOARDOUTLINE_FROM_SEL_PRIMS")
RunProcess("PCB:PlaceBoardOutline")
Call AddStringParameter("Size", "2.500MM")
RunProcess("PCB:SnapGrid")
Call AddStringParameter("MeasurementUnit", "Toggle")
RunProcess("PCB:DocumentPreferences")
End Sub
Sub Button1Click(Sender)
call Start_PCBServer() 'Start PCBServer
Board_chang = Round(Edit1.Text)
Iter_Num = Round(Edit3.Text) 'Get Iteration Number
call Set_Origin() 'Set Shape Relative to the origin
call Paint_Rectangle(-Board_chang/2,-Board_chang/2,Board_chang/2,Board_chang/2)
Call Board_Shape()
Call Y_Shape(0,0,30,4)
Action_Redraw()
Close
End Sub
Sub Y_Shape(x,y,L,Iter_Num)
a = PI/4
L1=L*2/3
If Iter_Num=0 Then 'If Iter_Num = 0
Call Y_Xing(x,y,L,L1,a) 'Draw Y
Else
Call Y_Xing(x,y,L,L1,a) 'Draw Y
Call Y_Shape(x-L1*sin(a),y+L+L1*cos(a),L/2,Iter_Num-1)
Call Y_Shape(x+L1*sin(a),y+L+L1*cos(a),L/2,Iter_Num-1)
End If
End Sub
Sub Y_Xing(x,y,L,L1,a)
Call Paint_Line(x,y,x,y+L) 'Draw Vertical Line
Call Paint_Line(x,y+L,x-L1*sin(a),y+L+L1*cos(a)) 'Draw Left Diagonal Line
Call Paint_Line(x,y+L,x+L1*sin(a),y+L+L1*cos(a)) 'Draw Right Diagonal Line
'Draw Left Y
Call Paint_Line(-y,x,-(y+L),x) 'Draw Vertical Line
Call Paint_Line(-(y+L),x,-(y+L+L1*cos(a)),x-L1*sin(a)) 'Draw Left Diagonal Line
Call Paint_Line(-(y+L),x,-(y+L+L1*cos(a)),x+L1*sin(a)) 'Draw Right Diagonal Line
'DraW Down Y
Call Paint_Line(x,-y,x,-(y+L)) 'Draw Vertical Line
Call Paint_Line(x,-(y+L),x-L1*sin(a),-(y+L+L1*cos(a))) 'Draw Left Diagonal Line
Call Paint_Line(x,-(y+L),x+L1*sin(a),-(y+L+L1*cos(a))) 'Draw Right Diagonal Line
'Draw Right Y
Call Paint_Line(y,-x,y+L,-x) 'Draw Vertical Line
Call Paint_Line(y+L,-x,y+L+L1*cos(a),-(x-L1*sin(a))) 'Draw Left Diagonal Line
Call Paint_Line(y+L,-x,y+L+L1*cos(a),-(x+L1*sin(a))) 'Draw Right Diagonal Line
End Sub
參考資料:
[1]付麗華.一種基於Y分形的平面微帶天線設計與優化[EB/OL].http://www.elecfans.com/soft/69/2019/20190412905256.html,2019.
[2] Altium Limited.PCB API Design Objects Interfaces[EB/OL].https://techdocs.altium.com/display/SCRT/PCB+API+Design+Objects+Interfaces,2017-9-13.