📄 chayangji.m
字号:
function varargout = chayangji(varargin)
% CHAYANGJI M-file for chayangji.fig
% CHAYANGJI, by itself, creates a new CHAYANGJI or raises the existing
% singleton*.
%
% H = CHAYANGJI returns the handle to a new CHAYANGJI or the handle to
% the existing singleton*.
%
% CHAYANGJI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CHAYANGJI.M with the given input arguments.
%
% CHAYANGJI('Property','Value',...) creates a new CHAYANGJI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before chayangji_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to chayangji_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help chayangji
% Last Modified by GUIDE v2.5 05-May-2006 16:08:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @chayangji_OpeningFcn, ...
'gui_OutputFcn', @chayangji_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 chayangji is made visible.
function chayangji_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 chayangji (see VARARGIN)
% Choose default command line output for chayangji
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes chayangji wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = chayangji_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 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)
axes(handles.axes1)
j=imread('chayangji.jpg');
% j=imresize(j,2.8,'bicubic');
imshow(j)
%%--栽植机--%%
%D点运动轨迹计算及其角速度计算
% alpha2--AB杆角度
% alpha3--BC杆角度
%dalpha2--AB杆角速度
%dalpha3--BC杆角速度
% (xc,yc)c点坐标
% (xa,ya)a点坐标
% (xb,yb)b点坐标
% (xd,yd)d点坐标
% clear
% clc
% xd(1,:)=zeros(1,215);%定义2维数组,存放x方向位移
% yd(1,:)=zeros(1,215);%定义2维数组,存放y方向位移
for i=1:215
R=100;L2=300;L3=300;
xc=250;yc=250;
w=280*pi/30;
t=linspace(0,3/14,215);
xa(1,i)=R*cos(w*t(i));
ya(1,i)=R*sin(w*t(i));
%xb=xa(1,i)+L2*cos(alpha2)=xc+L3*cos(alpha3)
%yb=ya(1,i)+L2*sin(alpha2)=yc+L3*sin(alpha3)
beta(1,i)=atan((ya(1,i)-yc)/(xa(1,i)-xc))+pi;%beta角度
s=(L3^2+(xc-xa(1,i))^2+(yc-ya(1,i))^2-L2^2)/(2*L3*sqrt((xc-xa(1,i))^2+(yc-ya(1,i))^2));
if s>0
alpha3(1,i)=beta(1,i)+atan(sqrt((1-s^2)/s));
elseif s<0
alpha3(1,i)=pi+beta(1,i)+atan(sqrt((1-s^2)/s));
end
% 下面计算alpha2
% cos(alpha2)=(xc+L3*cos(alpha3(1,i))-xa(1,i))/L2;
s1=(xc+L3*cos(alpha3(1,i))-xa(1,i))/L2;
if s1>0
alpha2(1,i)=atan(sqrt((1-s1^2)/s1));
elseif s1<0
alpha2(1,i)=pi+atan(sqrt((1-s1^2)/s1));
end
%----------------------------------------
%下面计算D点轨迹---按30度计算
xd(1,i)=xa(1,i)-300*cos(alpha2(1,i)-pi);
yd(1,i)=ya(1,i)-300*sin(alpha2(1,i)-pi);
%-----------------------------------------
%下面计算角速度
dxa(1,i)=-R*w*sin(w*t(i));
dya(1,i)=R*w*cos(w*t(i));
dalpha2(1,i)=(dxa(1,i)*cos(alpha3(1,i))+dya(1,i)*sin(alpha3(1,i)))/(L2*sin(alpha2(1,i)-alpha3(1,i)));
dalpha3(1,i)=(dxa(1,i)*cos(alpha2(1,i))+dya(1,i)*sin(alpha2(1,i)))/(L3*sin(alpha2(1,i)-alpha3(1,i)));
end
% axis off
% if get(gcbo,'Value');
% get('Tag',Axes2)
% end
hold on %必须加上才能在4各axes中画上图
axes(handles.axes2)
plot(xd(1,:),yd(1,:),'g*')
grid on
xlabel('X轴位移')
ylabel('Y轴位移')
% title('D点轨迹图')
% axis off
axis equal
axes(handles.axes3)
plot(w*t(1,:),dalpha2(1,:),'b*',w*t(1,:),dalpha3(1,:),'ro')
xlabel('wt')
ylabel('alpha')
% title('0--2pi内角速度图')
legend('AB杆角速度','BC杆角速度')
axis([0 6.28 -inf inf])
set(gca,'XTick',linspace(0,6.28,7))
set(gca,'XTickLabel',{'0','pi/3','2pi/3','pi','4pi/3','5pi/3','2pi'})
hold off
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(gcbf);
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -