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
|
%------------------------------------------------------------------------
% Draws a representation of a lens at the position and angle specified.
%
% SYNTAX: [handle,texthandle,pos,rotpos]
% =lensplot(d <,t,x,y,theta,lambda,label,labelpos,suppress>);
%
% INPUT ARGUMENTS:
% d = diameter of the lens. The lens radius of curvature is assumed
% to be essentially infinite (1e30).
% d can also be passed as a 2-element vector d=[diameter,radius],
% where the first element is the lens diameter and the second
% is the radius of curvature of the lens surface.
% t = additional lens thickness (same units as the diameter)
% x,y = x,y - position offset, default=0,0.
% theta = rotation of optic axis counterclockwise relative to x-axis,
% defaul=0
% lambda = wavelength, default=1064 nm
% label = string with which to label the lens, default is ''.
% labelpos = 0 to put label at bottom, 1 to put label at top, default 0
% suppress = set to 1 to suppress plotting, default 0.
%
% OUTPUT ARGUMENTS:
% handle = handle of the trace plotted
% texthandle= handle of the text label if supplied (otherwise -1)
% pos = 2xn matrix. Second row is lens face height, first row is
% the corresponding position along the optic axis, measured
% from the point at which q is specified.
% rotpos = 2xn matrix. x,y coordinates of the lens trace,
% first row corresponds to x coord's, second row to y coord's.
%
% Last Modified: Dec. 10, 2003 by Andri M. Gretarsson.
%
%-------------------------------------------------------------------------
% SYNTAX: [handle,texthandle,pos,rotpos]
% =lensplot(d <,t,x,y,theta,lambda,label,labelpos,suppress>);
%-------------------------------------------------------------------------
function [handle,texthandle]=lensplot(d,varargin)
if size(d,2)>1, Rlens=d(2); else Rlens=1e30; end
if nargin>=2, t=varargin{1}; else t=0; end
if nargin>=3, x=varargin{2}; else x=0; end
if nargin>=4, y=varargin{3}; else y=0; end
if nargin>=5, theta=varargin{4}*pi/180; else theta=0; end
if nargin>=6, lambda=varargin{5}; else lambda=1064e-9; end
if nargin>=7, label=varargin{6}; else label=''; end
if nargin>=8, labelpos=varargin{7}; else labelpos=0; end
if nargin>=9, suppress=varargin{8}; else suppress=0; end
lensheight=d(1)/2;
phimax=asin(lensheight/Rlens);
phi=-phimax:phimax/100:phimax;
if Rlens>=0
curvethickness=abs(Rlens-Rlens*cos(phimax));
xleftside=Rlens*(cos(phimax)-cos(phi))+curvethickness;
xrightside=-Rlens*(cos(phimax)-cos(phi))+curvethickness+t;
xtop=[max(xleftside),min(xrightside)];
xbottom=[max(xleftside),min(xrightside)];
xcenter=t/2+curvethickness;
else
curvethickness=abs(Rlens-Rlens*cos(phimax));
xleftside=Rlens*(cos(phimax)-cos(phi));
xrightside=-Rlens*(cos(phimax)-cos(phi))+t+2*curvethickness;
xtop=[min(xleftside),max(xrightside)];
xbottom=[min(xleftside),max(xrightside)];
xcenter=curvethickness+t/2;
end
yleftside=Rlens*sin(phi);
yrightside=yleftside;
rightside=[xrightside;yrightside];
leftside=[xleftside;yleftside];
top=[xtop;[max(yleftside),max(yrightside)]];
bottom=[xbottom;[min(yleftside),min(yrightside)]];
rotmat=[[cos(theta), -sin(theta)];[sin(theta), cos(theta)]];
rotrightside=rotmat*(rightside-[ones(size(rightside(1,:)))*xcenter;zeros(size(rightside(2,:)))]);
rotleftside=rotmat*(leftside-[ones(size(rightside(1,:)))*xcenter;zeros(size(rightside(2,:)))]);
rottop=rotmat*(top-[ones(size(top(1,:)))*xcenter;zeros(size(top(2,:)))]);
rotbottom=rotmat*(bottom-[ones(size(bottom(1,:)))*xcenter;zeros(size(bottom(2,:)))]);
rotrightside(1,:)=rotrightside(1,:)+x+xcenter;
rotrightside(2,:)=rotrightside(2,:)+y;
rotleftside(1,:)=rotleftside(1,:)+x+xcenter;
rotleftside(2,:)=rotleftside(2,:)+y;
rottop(1,:)=rottop(1,:)+x+xcenter;
rottop(2,:)=rottop(2,:)+y;
rotbottom(1,:)=rotbottom(1,:)+x+xcenter;
rotbottom(2,:)=rotbottom(2,:)+y;
switch labelpos
case 2,
augmentedlabel=[' ',label];
xtextpos=max(rotrightside(1,:));
ytextpos=( min(rotrightside(2,:)) + max(rotrightside(2,:)) )/2;
case 0,
augmentedlabel=strvcat(' ',label); %#ok<VCAT>
xtextpos=max(rotrightside(1,:));
ytextpos=min(rotrightside(2,:));
case 1,
augmentedlabel=strvcat(label,' '); %#ok<VCAT>
xtextpos=max(rotrightside(1,:));
ytextpos=max(rotrightside(2,:));
end
if suppress~=1
handle=plot(rotrightside(1,:),rotrightside(2,:),'k-',...
rotleftside(1,:),rotleftside(2,:),'k-',...
rottop(1,:),rottop(2,:),'k-',...
rotbottom(1,:),rotbottom(2,:),'k-');
if ~isempty(label)
texthandle=text(xtextpos,ytextpos,augmentedlabel);
else
texthandle=-1;
end
end
|