标题: 空对空导弹系统 [打印本页] 作者: matlab的旋律 时间: 2017-6-5 11:23 标题: 空对空导弹系统 function varargout = main_figure(varargin)
% MAIN_FIGURE MATLAB code for main_figure.fig
% MAIN_FIGURE, by itself, creates a new MAIN_FIGURE or raises the existing
% singleton*.
%
% H = MAIN_FIGURE returns the handle to a new MAIN_FIGURE or the handle to
% the existing singleton*.
%
% MAIN_FIGURE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN_FIGURE.M with the given input arguments.
%
% MAIN_FIGURE('Property','Value',...) creates a new MAIN_FIGURE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_figure_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_figure_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 main_figure
% Last Modified by GUIDE v2.5 05-Jun-2017 08:58:47
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_figure_OpeningFcn, ...
'gui_OutputFcn', @main_figure_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 main_figure is made visible.
function main_figure_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 main_figure (see VARARGIN)
% Choose default command line output for main_figure
handles.output = hObject;
% UIWAIT makes main_figure wait for user response (see UIRESUME)
% uiwait(handles.figure_tag);
% --- Outputs from this function are returned to the command line.
function varargout = main_figure_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 button press in begin_tag.
function begin_tag_Callback(hObject, eventdata, handles)
% hObject handle to begin_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global VM Angle_m
e1 = str2num(handles.e1_tag.String);
% e2 = str2num(handles.e2_tag.String);
Angle_m = str2num(handles.angle_m_tag.String);
VM = str2num(handles.vm_tag.String);
e3 = str2num(handles.e3_tag.String);
e4 = str2num(handles.e4_tag.String);
% --- Executes on button press in quit_tag.
function quit_tag_Callback(hObject, eventdata, handles)
% hObject handle to quit_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(main_figure)
function e1_tag_Callback(hObject, eventdata, handles)
% hObject handle to e1_tag (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,'String') returns contents of e1_tag as text
% str2double(get(hObject,'String')) returns contents of e1_tag as a double
% --- Executes during object creation, after setting all properties.
function e1_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to e1_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function e2_tag_Callback(hObject, eventdata, handles)
% hObject handle to e2_tag (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,'String') returns contents of e2_tag as text
% str2double(get(hObject,'String')) returns contents of e2_tag as a double
% --- Executes during object creation, after setting all properties.
function e2_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to e2_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function angle_m_tag_Callback(hObject, eventdata, handles)
% hObject handle to angle_m_tag (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,'String') returns contents of angle_m_tag as text
% str2double(get(hObject,'String')) returns contents of angle_m_tag as a double
% --- Executes during object creation, after setting all properties.
function angle_m_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to angle_m_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function vm_tag_Callback(hObject, eventdata, handles)
% hObject handle to vm_tag (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,'String') returns contents of vm_tag as text
% str2double(get(hObject,'String')) returns contents of vm_tag as a double
% --- Executes during object creation, after setting all properties.
function vm_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to vm_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function e3_tag_Callback(hObject, eventdata, handles)
% hObject handle to e3_tag (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,'String') returns contents of e3_tag as text
% str2double(get(hObject,'String')) returns contents of e3_tag as a double
% --- Executes during object creation, after setting all properties.
function e3_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to e3_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function e4_tag_Callback(hObject, eventdata, handles)
% hObject handle to e4_tag (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,'String') returns contents of e4_tag as text
% str2double(get(hObject,'String')) returns contents of e4_tag as a double
% --- Executes during object creation, after setting all properties.
function e4_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to e4_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function height_tag_Callback(hObject, eventdata, handles)
% hObject handle to height_tag (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,'String') returns contents of height_tag as text
% str2double(get(hObject,'String')) returns contents of height_tag as a double
% --- Executes during object creation, after setting all properties.
function height_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to height_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function external_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to external_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function internal_tag_CreateFcn(hObject, eventdata, handles)
% hObject handle to internal_tag (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
global M Density Cx0 S VM Angle_m P
pRightK(1) = (iY(3)*sin(iY(1) - iY(4))-VM*sin(iY(1)-Angle_m))/iY(2);
pRightK(2) = VM*cos(iY(1) - Angle_m) - iY(3)*cos(iY(1) - iY(4));
pRightK(3) = (P - 0.5*iY(3)*iY(3)*Density*S*Cx0)/M;
pRightK(4) = 4*pRightK(1);
end
function [tempX,pOY] = LgktSoulution(iX,iY,h)
Count=1;
tempX=iX;
tempY = iY;
pOY = iY;
while (Count>0)
K1 = RightSlopeFun(tempX,tempY);
tempX = tempX + h/2;
for i=0:4-1
pOY(i+1)=tempY(i+1)+K1(i+1)*h/2;
end
K2 = RightSlopeFun(tempX,pOY);
for i=0:4-1
pOY(i+1)=tempY(i+1)+K2(i+1)*h/2;
end
% RightSlopeFun(K3,tempX,pOY);
K3 = RightSlopeFun(tempX,pOY);
tempX = tempX + h/2;
for i=0:4-1
pOY(i+1)=tempY(i+1)+K3(i+1)*h;
end
K4 = RightSlopeFun(tempX,pOY);
for i=0:4-1
pOY(i+1)=tempY(i+1)+h*(K1(i+1)+2*K2(i+1)+2*K3(i+1)+K4(i+1))/6;
end
Count = Count - 1;
if (Count<=0)
break;
end
tempY= pOY;
end
function m_ptOrigin = getAirToAirTrace(e1,Angle_m,VM,e3,e4)
global DR M Density Cx0 S P
DR = 500;
M = 86.6;
Density = 1.225*0.159;
Cx0 = 1.4*0.5;
S = 0.32*0.32*pi;
q = 0;
R = 0;
for k = 0:40-1
r = e1;
for w=1:50
ix = 0;
iy = [Angle_m + pi - q, r, e3, Angle_m + pi - q - e4];
X0 = -iy(2)*cos(iy(1));
Y0 = -iy(2)*sin(iy(1)); %导弹初始坐标
X1 = 0;
Y1 = 0; %目标初始坐标(原点)
for i = 1:3000 - 1
if (i < 500)
P = 31*9.754*M;
else
P = 0;
end
X0 = X0 + iy(3)*0.01*cos(iy(4));
Y0 = Y0 + iy(3)*0.01*sin(iy(4)); %导弹坐标更新
X1 = X1 + VM*0.01*cos(Angle_m);
Y1 = Y1 + VM*0.01*sin(Angle_m); %目标位置更新
[ix,iy] = LgktSoulution(ix,iy,0.01);
r0 = sqrt((X1 - X0)*(X1 - X0) + (Y1 - Y0)*(Y1 - Y0));
if (iy(2)<30)
break;
end
end
if (iy(2)>30)
r=r-DR; %更新距离
else
break;
end
end
R=r;
m_ptOrigin(k+1,: ) = [ -R*cos(Angle_m + pi - q)/100,R*sin(Angle_m + pi-q)/100];
if (q < 2*pi)
q = q +15*pi/180;%更新进入角
end
end
m_ptOrigin(end,: ) = m_ptOrigin(1,: );