function varargout = Traslacion_01(varargin)
% TRASLACION_01 MATLAB code for Traslacion_01.fig
%      TRASLACION_01, by itself, creates a new TRASLACION_01 or raises the existing
%      singleton*.
%
%      H = TRASLACION_01 returns the handle to a new TRASLACION_01 or the handle to
%      the existing singleton*.
%
%      TRASLACION_01('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TRASLACION_01.M with the given input arguments.
%
%      TRASLACION_01('Property','Value',...) creates a new TRASLACION_01 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Traslacion_01_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Traslacion_01_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 Traslacion_01

% Last Modified by GUIDE v2.5 15-Nov-2013 09:59:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Traslacion_01_OpeningFcn, ...
                   'gui_OutputFcn',  @Traslacion_01_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
global incremento;
% End initialization code - DO NOT EDIT


% --- Executes just before Traslacion_01 is made visible.
function Traslacion_01_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 Traslacion_01 (see VARARGIN)

% Choose default command line output for Traslacion_01
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Traslacion_01 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Traslacion_01_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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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 popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (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



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 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 edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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 popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
global incremento;
incremento = get(handles.slider1,'Value');
set(handles.text9,'String',num2str(incremento));
% 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


% --- 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


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global incremento;
eje = get(handles.popupmenu1, 'Value');
angulo = get(handles.edit3,'String');
angulo = str2num(angulo);
angulo = angulo/57.3;
funcion = get(handles.popupmenu2,'Value');

t = 0:0.1:2*pi;
[x,y] = meshgrid(t,t);
z1 = sin(x) + cos(y);
z2 = x.^.5+y.^.5+sin(x.^2)+cos(y);
z3 = x/10+sin(x.*y)-x.^2/10;
m = size(x,1);
n = size(x,2);
x = x(:);
y = y(:);

vector = get(handles.edit2,'String');
vector = str2num(vector);
norma = norm(vector);

if norma==0
    vector = [0 0 1];
    set(handles.edit2,'String',num2str(vector));
end

vector = vector/norma;

switch funcion
    case 1
        z = z1;
        z = z(:);
        titulo = 'z = sin(x) + cos(y)';
    case 2
        z = z2;
        z = z(:);
        titulo = 'z = sqrt(x) + sqrt(y) + sin(x^2) + cos(y)';
    case 3
        z = z3;
        z = z(:);
        titulo = 'z = x/10 + sin(xy) - (x^2)/10';
end

trayectoria = get(handles.popupmenu3,'Value');
theta = linspace(0,2*pi,m*n);
theta = theta';
o = [theta theta theta];
r = 4;

switch trayectoria
    case 1
        o1 = 0*r*cos(theta);
        o2 = 0*r*sin(theta);
        o3 = 0*theta;
        o = [o1 o2 o3];
    case 2
        o1 = r*cos(theta);
        o2 = r*sin(theta);
        o3 = 0*theta;
        o = [o1 o2 o3];
    case 3
        o1 = r*cos(theta);
        o2 = r*sin(theta);
        o3 = 4*sin(6*theta);
        o = [o1 o2 o3];
end

datos = [x y z];

incremento = get(handles.slider1,'Value');
incremento = incremento*150+50;
incremento = round(incremento);

angulo_vector = linspace(0,angulo,m*n);

if angulo>0  
for i=1:incremento:m*n
    [xr,yr,zr] = traslacion(eje,angulo_vector(i),vector,datos,o(i,:),m,n);
    surf(xr,yr,zr),hold on
    plot3(o(:,1),o(:,2),o(:,3),'LineWidth',3),hold off
    xlabel('Eje x','Color','red','FontSize',14,'FontWeight','bold')
    ylabel('Eje y','Color','red','FontSize',14,'FontWeight','bold')
    zlabel('Eje z','Color','red','FontSize',14,'FontWeight','bold')
    title(titulo,...
           'Color','blue','FontSize',14,'FontWeight','bold')
   axis([-3 15 -2 10 -14 14])
   pause(.001)
end
end

if angulo<0  
for i=1:incremento:m*n
    [xr,yr,zr] = traslacion(eje,angulo_vector(i),vector,datos,o(i,:),m,n);
    surf(xr,yr,zr),hold on
    plot3(o(:,1),o(:,2),o(:,3),'LineWidth',3),hold off
    xlabel('Eje x','Color','red','FontSize',14,'FontWeight','bold')
    ylabel('Eje y','Color','red','FontSize',14,'FontWeight','bold')
    zlabel('Eje z','Color','red','FontSize',14,'FontWeight','bold')
    title(titulo,...
           'Color','blue','FontSize',14,'FontWeight','bold')
   axis([-3 15 -2 10 -14 14])
   pause(.001)
end
end


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
close(gcbf)


% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
a = imread('Fig_01.png');
imshow(a);
axis off;
% hObject    handle to axes1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1


% --- Executes on selection change in popupmenu3.
function popupmenu3_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 popupmenu3_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
