function varargout = coor_trans(varargin)
% COOR_TRANS MATLAB code for coor_trans.fig
% COOR_TRANS, by itself, creates a new COOR_TRANS or raises the existing
% singleton*.
%
% H = COOR_TRANS returns the handle to a new COOR_TRANS or the handle to
% the existing singleton*.
%
% COOR_TRANS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in COOR_TRANS.M with the given input arguments.
%
% COOR_TRANS('Property','Value',...) creates a new COOR_TRANS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before coor_trans_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to coor_trans_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 coor_trans
% Last Modified by GUIDE v2.5 24-Mar-2019 21:04:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @coor_trans_OpeningFcn, ...
'gui_OutputFcn', @coor_trans_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 coor_trans is made visible.
function coor_trans_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 coor_trans (see VARARGIN)
% Choose default command line output for coor_trans
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes coor_trans wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = coor_trans_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 selection change in popupmenu3.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over text1.
function text1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to text1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%调用a,f
a = get(handles.text_a_value,'string');
f = get(handles.text_f_value,'string');
a = str2double(a);
f = str2double(f);
e=sqrt(2*f-f^2);
%此处考虑两种情况:1.输入为大地坐标;2.输入为空间直角坐标
%根据单选按钮的value值是否为1来判断
val = get(handles.radiobutton2,'value');
if val == 0
%输入为大地坐标
B = get(handles.edit1,'string');
L = get(handles.edit2,'string');
H = get(handles.edit3,'string');
B = str2double(B);
L = str2double(L);
H = str2double(H);
L=L/180*pi;
B=B/180*pi;
N=a/(sqrt(1-e*e*sin(B)*sin(B)));
X=(N+H)*cos(B)*cos(L);
Y=(N+H)*cos(B)*sin(L);
Z=(N*(1-e^2)+H)*sin(B);
X = num2str(X,13);
Y = num2str(Y,13);
Z = num2str(Z,13);
set(handles.edit4,'string',X)
set(handles.edit5,'string',Y)
set(handles.edit6,'string',Z)
else
%输入为空间直角坐标
X = get(handles.edit1,'string');
Y = get(handles.edit2,'string');
Z = get(handles.edit3,'string');
X = str2double(X);
Y = str2double(Y);
Z = str2double(Z);
% 计算大地经度
if X~=0||Y~=0
if X>0&&Y>=0
L=atan(Y/X);
elseif X>0&&Y<0
L=-atan(Y/X);
elseif X<0&&Y>=0
L=pi+atan(Y/X);
elseif X<0&&Y<0
L=-pi+atan(Y/X);
elseif X==0
if Y>0
L=pi/2;
else
L=-pi/2;
end
end
end
L = L/pi*180;
L = num2str(L,8);
set(handles.edit5,'string',L)
% 计算大地纬度
delta=1;
if X~=0||Y~=0
tb0=Z/sqrt(X^2+Y^2);
while abs(delta)>=5*10^(-10)
tb=1/sqrt(X^2+Y^2)*(Z+a*e^2*tb0/sqrt(1+(1-e^2)*tb0^2));
delta=tb0-tb;
tb0=tb;
end
B=atan(tb);
end
% 计算大地高
N=a/(sqrt(1-e*e*sin(B)*sin(B)));
H=sqrt(X^2+Y^2)/cos(B)-N;
B = B/pi*180;
B = num2str(B,8);
set(handles.edit4,'string',B)
H = num2str(H,8);
set(handles.edit6,'string',H)
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a futur