Created
January 29, 2010 19:40
-
-
Save jfhbrook/290034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%mirror.m | |
%calculates mirror geometry action for MTUAF | |
function main() | |
%inputs, Units in inches | |
b=cart2both([-0.5,-0.5]); %bottom of screen | |
[th,r]=pol2cart(deg2rad(90),0.5*12); %top of screen | |
a=[th,r]+b{1}; | |
topangle=deg2rad(40);%top inside angle | |
bottomangle=deg2rad(100);%bottom inside angle | |
m_dist=12;%distance down c where mirror starts | |
m_angle=deg2rad(38);%angle of mirror | |
%calculations | |
afromb=cart2both(a{1}-b{1}); | |
aasa=asa(topangle,afromb{2}(2),bottomangle); %intermediate for finding c | |
%c represents focus without mirror | |
%THIS IS WRONG | |
c=pol2both([bottomangle-afromb{2}(1), aasa(1)]); %length | |
m_bot=cart2both((m_dist/c{2}(2))*c{1});%bottom of mirror | |
m_botfromb=cart2both(m_bot{1}-b{1}); | |
[sass1,sass2]=sas(afromb{2}(2),bottomangle,m_botfromb{2}(2)); | |
[sasstheta,sassr]=pol2cart(sass2,-sass1); | |
%THIS IS WRONG | |
m_top=cart2both(m_bot{1} + ... | |
[sasstheta,sassr] + ... %side-angle-side | |
[pi+m_botfromb{2}(1),0]); %add to angle for proper orientation | |
F=cart2both(refl(c{1}-m_bot{1},m_top{1}-m_bot{1})+m_bot{1});%focus using reflection formula | |
%create some sets to plot | |
%sansmirror=vertcat(a{1},b{1},c{1},a{1}) | |
screen=vertcat(a{1},b{1}); | |
oldlight=vertcat(a{1},c{1},b{1}); | |
mirror=vertcat(m_bot{1},m_top{1}); | |
lightbox=vertcat(b{1},m_bot{1},F{1},m_top{1},a{1}); | |
plot(screen(:,1),screen(:,2),'--r'); | |
hold on; | |
plot(mirror(:,1),mirror(:,2),'--r'); | |
plot(oldlight(:,1),oldlight(:,2)); | |
%plot(lightbox(:,1),lightbox(:,2)); | |
hold off; | |
%helpeur fxn's | |
function w=refl(u,v) %thx wikipedia for equation | |
%reflection of u over v | |
%where u and v are of form [x,y] | |
w=(2*dot(u,v)/dot(v,v))*v-u; | |
end | |
function x=cart2both(xcart) | |
[theta,r]=cart2pol(xcart(1),xcart(2)); | |
x={xcart,[theta,r]}; | |
end | |
function x=pol2both(xpol) | |
[x,y]=pol2cart(xpol(1),xpol(2)); | |
x={[x,y],xpol}; | |
end | |
function [a,gamma,b]=asa(alpha,c,beta) | |
%ASA geometry action | |
gamma=pi-alpha-beta; | |
a=c*sin(alpha)/sin(gamma); | |
b=c*sin(beta)/sin(gamma); | |
end | |
function [alpha,c,beta]=sas(a,gamma,b) | |
%SAS geometry action | |
c=sqrt(a^2+b^2-2*a*b*cos(gamma)); | |
alpha=asin((a/c)*sin(gamma)); | |
beta=asin((b/c)*sin(gamma)); | |
end | |
function rad=deg2rad(deg) | |
rad=deg*pi/180.0; | |
end | |
function deg=rad2deg(rad) | |
deg=rad*180/pi; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment