summaryrefslogtreecommitdiff
path: root/openEMS/matlab/AddMRStub.m
blob: 432fa6a88958a17c972430364e7dd34ced76140e (plain)
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
function CSX = AddMRStub( CSX, materialname, prio, MSL_width, len, alpha, resolution, orientation, normVector, position )
% CSX = AddMRStub( CSX, materialname, prio, MSL_width, len, alpha,
% resolution, orientation, normVector, position )
%
% Microstrip Radial Stub
%
% CSX: CSX-object created by InitCSX()
% materialname: property for the MSL (created by AddMetal() or AddMaterial())
% prio: priority
% MSL_width: width of the MSL to connect the stub to
% len: length of the radial stub
% alpha: angle subtended by the radial stub (degrees) 
% resolution: discrete angle spacing (degrees)
% orientation: angle of main direction of the radial stub (degrees)
% normVector: normal vector of the stub
% position: position of the end of the MSL
%
% This radial stub definition is equivalent to the one Agilent ADS uses.
%
% example:
% CSX = AddMRStub( CSX, 'PEC', 10, 1000, 5900, 30, 1, -90, [0 0 1], [0 -10000 254] );
%
%
% Sebastian Held <sebastian.held@gmx.de>
% Jun 1 2010
%
% See also InitCSX AddMetal AddMaterial

% check normVector
if ~(normVector(1) == normVector(2) == 0) && ...
        ~(normVector(1) == normVector(3) == 0) && ...
        ~(normVector(2) == normVector(3) == 0) || (sum(normVector) == 0)
	error 'normVector must have exactly one component ~= 0'
end
normVector = normVector ./ sum(normVector); % normVector is now a unit vector

% convert angles to radians
alpha_rad = alpha/180*pi;
orientation_rad = orientation/180*pi;
resolution_rad = resolution/180*pi;

%
% build stub at origin (0,0,0) and translate/rotate it later
%

D = 0.5 * MSL_width / sin(alpha_rad/2);
R = cos(alpha_rad/2) * D;

% point at the center of the MSL
p(1,1) = 0;
p(2,1) = -MSL_width/2;
p(1,2) = 0;
p(2,2) = MSL_width/2;

for a = alpha_rad/2 : -resolution_rad : -alpha_rad/2
    p(1,end+1) = cos(a) * (D+len) - R;
    p(2,end)   = sin(a) * (D+len);
end

% rotate
rot = [cos(-orientation_rad), -sin(-orientation_rad); sin(-orientation_rad), cos(-orientation_rad)];
p = (p.' * rot).';

% translate
idx_elevation = [1 2 3];
idx_elevation = idx_elevation(normVector>0);
dim1 = mod( idx_elevation, 3 ) + 1;
dim2 = mod( idx_elevation+1, 3 ) + 1;
p(1,:) = p(1,:) + position(dim1);
p(2,:) = p(2,:) + position(dim2);

elevation = position(idx_elevation);
CSX = AddPolygon( CSX, materialname, prio, normVector, elevation, p );