function varargout = test2(varargin)
% TEST2 MATLAB code for test2.fig
% TEST2, by itself, creates a new TEST2 or raises the existing
% singleton*.
%
% H = TEST2 returns the handle to a new TEST2 or the handle to
% the existing singleton*.
%
% TEST2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST2.M with the given input arguments.
%
% TEST2('Property','Value',...) creates a new TEST2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help test2
% Last Modified by GUIDE v2.5 14-Apr-2022 23:19:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test2_OpeningFcn, ...
'gui_OutputFcn', @test2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before test2 is made visible.
function test2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to test2 (see VARARGIN)
% Choose default command line output for test2
handles.output = hObject;
position = get(handles.pushbutton1,'Position');
I = imread('1.png'); %读取图片
I = imresize(I, [position(4)*1 position(3)*1.1]); %设置位置 第一个pos是高 第二个是宽(只能是整数)
set(handles.pushbutton1,'CData',I); %将按钮的背景图片设置成I
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.edit1,'string',num2str(get(hObject,'value'))); %把滑块1的当前值转换成字符,string给edit1
fplot(handles.axes1,@(x) 0*x,[-260 0]*1,'Linewidth',1.5,'color',[0 0 0]/255); %画主光轴
hold on;
t=-pi/2:0.1:pi/2;R=100; %画反射镜
x=R*cos(t)-100;y=R*sin(t);
plot(x,y,'color',[0 0 0]/255,'Linewidth',3);
Ob_distance=-get(hObject,'value'); %物距
plot(handles.axes1,[Ob_distance Ob_distance],[0 40],'color',[0 0 0]/255,'Linewidth',2.5); %画物
Im_distance=1/(-0.02-(1/Ob_distance)); %像距
set(handles.text5,'string',Im_distance); %显示出像距
Im_height=(-Im_distance/Ob_distance)*40; %像高
set(handles.text14,'string',Im_height); %显示出像高
plot(handles.axes1,[Im_distance Im_distance],[0 Im_height],'--','color',[0 0 0]/255,'Linewidth',2.5); %画像
%plot(handles.axes1,[Ob_distance Im_distance],[40 Im_height],'color',[0 0 255]/255,'Linewidth',2); %画物像光线BB'
%plot(handles.axes1,[-100 Ob_distance],[0 40],'--','color',[0 0 255]/255,'Linewidth',2); %画物像光线BC
%plot(handles.axes1,[-100+5*(100+Im_distance) Im_distance],[Im_height*5 Im_height],'color',[255 0 0]/255,'Linewidth',2); %画辅助光线
if(Im_distance<0&&Ob_distance<Im_distance)
plot(handles.axes1,[Ob_distance Im_distance],[40 Im_height],'color',[0 0 255]/255,'Linewidth',2); %画物像光线BB'
plot(handles.axes1,[-100+5*(100+Im_distance) Im_distance],[Im_height*5 Im_height],'color',[0 0 255]/255,'Linewidth',2); %画辅助光线
end
if(Ob_distance<0&&Ob_distance>Im_distance)
plot(handles.axes1,[Ob_distance Im_distance],[40 Im_height],'color',[0 0 255]/255,'Linewidth',2); %画物像光线BB'
plot(handles.axes1,[-100+5*(100+Ob_distance) Ob_distance],[40*5 40],'color',[0 0 255]/255,'Linewidth',2); %画辅助光线
end
if(Ob_distance<0&&Im_distance>0)
plot(handles.axes1,[Ob_distance Im_distance],[40 Im_height],'color',[0 0 255]/255,'Linewidth',2); %画物像光线BB'
plot(handles.axes1,[-100 Ob_distance],[0 40],'color',[0 0 255]/255,'Linewidth',2); %画辅助光线CB
end
text(handles.axes1,-100,7,'C','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman'); %画字母C
text(handles.axes1,-102,0,'·','Linewidth',3,'fontsize',30,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman'); %画球心
text(handles.axes1,0,0,'O','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman'); %画字母O
text(handles.axes1,-30,90,'凹面反射镜','Linewidth',3,'fontsize',15,'color',[0 0 0]/255,'FontAngle','italic','fontname','MS Sans Serif'); %画标题“凹面反射镜”
text(handles.axes1,-250,90,'物方光线BC','Linewidth',3,'fontsize',15,'color',[0 0 0]/255,'FontAngle','italic','fontname','MS Sans Serif'); %画标题“物方光线BC”
text(handles.axes1,Ob_distance+2,7,'A','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman'); %画 AB
text(handles.axes1,Ob_distance+2,45,'B','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman');
text(handles.axes1,Im_distance+2,-5,'A^{,}','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman'); %画 A'B'
text(handles.axes1,Im_distance+2,Im_height-5,'B^{,}','Linewidth',3,'fontsize',20,'color',[0 0 0]/255,'FontAngle','italic','fontname','Times New Roman');
axis equal; %划定显示窗口范围
ylim(handles.axes1,[-90 90]);
xlim(handles.axes1,[-260 0]);
axis off;
hold off;
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function edit1_Callback(hObject, eventdata,