Code covered by the BSD License  

Highlights from
3 shot dynamic balancing

image thumbnail

3 shot dynamic balancing

by

 

06 Nov 2006 (Updated )

it gives exact position and amount of mass to be added or removed for dynamic balancing

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

% Last Modified by GUIDE v2.5 12-Jun-2006 22:50:35

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @shot3_OpeningFcn, ...
                   'gui_OutputFcn',  @shot3_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 shot3 is made visible.
function shot3_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 shot3 (see VARARGIN)
set(handles.inidisplace,'string','')
set(handles.tmass,'string','')
set(handles.displace0,'string','')
set(handles.displace120,'string','')
set(handles.displace240,'string','')
axis off
% Choose default command line output for shot3
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = shot3_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;



function tmass_Callback(hObject, eventdata, handles)
% hObject    handle to tmass (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ax1=gca;
delete(ax1)
handles.tmass=str2double(get(hObject,'String'));
if isnan(handles.tmass) || handles.tmass==0
    errordlg('Enter Valid Data','Warning')
end
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of tmass as text
%        str2double(get(hObject,'String')) returns contents of tmass as a double


% --- Executes during object creation, after setting all properties.
function tmass_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tmass (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function displace0_Callback(hObject, eventdata, handles)
% hObject    handle to displace0 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.amp0=str2double(get(hObject,'String'));
if isnan(handles.amp0) || handles.amp0==0
    errordlg('Enter Valid Data','Warning')
end
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of displace0 as text
%        str2double(get(hObject,'String')) returns contents of displace0 as a double


% --- Executes during object creation, after setting all properties.
function displace0_CreateFcn(hObject, eventdata, handles)
% hObject    handle to displace0 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function displace120_Callback(hObject, eventdata, handles)
% hObject    handle to displace120 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.amp120=str2double(get(hObject,'String'));
if isnan(handles.amp120) || handles.amp120==0
    errordlg('Enter Valid Data','Warning')
end
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of displace120 as text
%        str2double(get(hObject,'String')) returns contents of displace120 as a double


% --- Executes during object creation, after setting all properties.
function displace120_CreateFcn(hObject, eventdata, handles)
% hObject    handle to displace120 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function displace240_Callback(hObject, eventdata, handles)
% hObject    handle to displace240 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.amp240=str2double(get(hObject,'String'));
if handles.amp240==nan || handles.amp240==0
    errordlg('Enter Valid Data','Warning')
end
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of displace240 as text
%        str2double(get(hObject,'String')) returns contents of displace240 as a double


% --- Executes during object creation, after setting all properties.
function displace240_CreateFcn(hObject, eventdata, handles)
% hObject    handle to displace240 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function inidisplace_Callback(hObject, eventdata, handles)
% hObject    handle to inidisplace (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.ampini=str2double(get(hObject,'String'));
if isnan(handles.ampini) || handles.ampini==0
    errordlg('Enter Valid Data','Warning')
end
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of inidisplace as text
%        str2double(get(hObject,'String')) returns contents of inidisplace as a double


% --- Executes during object creation, after setting all properties.
function inidisplace_CreateFcn(hObject, eventdata, handles)
% hObject    handle to inidisplace (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on button press in analyze.
function analyze_Callback(hObject, eventdata, handles)
% hObject    handle to analyze (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
amp0=handles.ampini;
tmass=handles.tmass;
amp1=handles.amp0;
amp2=handles.amp120;
amp3=handles.amp240;
if isnan(amp0) || isnan(tmass) || isnan(amp1) || isnan(amp2) || isnan(amp3)
    errordlg('Data Entered Not Valid','Error')
    elseif  amp3>amp0 || amp2>amp0 || amp1>amp0
        create.WindowStyle='replace';
    create.Interpreter='tex';
    msgbox('Trial displacements can\primet be greater than initial displacements','Invalid Data','error',create)
else
%This program is based on 3 shot method used for dynamic balancing
%plotting
cla;
for i=1:1:361
[x0 y0]=pol2cart((i-1)*pi/180,amp0);
if i==1
    a1=x0; b1=y0;
end
if i==121
    a2=x0; b2=y0;
end
if i==241
    a3=x0; b3=y0;
end
xc0(i)=x0; yc0(i)=y0;
end
for i=1:1:361
[x1 y1]=pol2cart((i-1)*pi/180,amp1);
xc1(i)=x1+amp0.*cosd(0); yc1(i)=y1+amp0.*sind(0);
end
for i=1:1:361
[x2 y2]=pol2cart((i-1)*pi/180,amp2);
xc2(i)=x2+amp0.*cosd(120); yc2(i)=y2+amp0.*sind(120);
end
for i=1:1:361
[x3 y3]=pol2cart((i-1)*pi/180,amp3);
xc3(i)=x3+amp0.*cosd(240); yc3(i)=y3+amp0.*sind(240);
end
%figure('Color',[1 1 1],'name','3 SHOT METHOD FOR CALCULATION OF UNBALANCED MASS    BY M.TAUHA ALI(ME-13)','numbertitle','off');
hold on
h2=plot(xc0,yc0,xc1,yc1,xc2,yc2,xc3,yc3);
axis ([-1*(amp0+amp1+amp2) amp0+amp1+amp2 -1*(amp0+amp1+amp2) amp0+amp1+amp2])
ha1=gca;handles.haxes=ha1;
da.XTick=[];
da.YTick=[];
da.Box='on';
set(ha1,da)
%axis off
axis square
line([-0.2 0.2],[0 0],'color','k','linewidth',2)
line([0 0],[-0.2 0.2],'color','k','linewidth',2)
line([a1.*cosd(0)-0.3 a1.*cosd(0)+0.3],[b1 b1],'color','k','linewidth',2)
line([a2-0.3*cosd(120) a2+0.3.*cosd(120)],[b2-0.3.*sind(120) b2+0.3.*sind(120)],'color','k','linewidth',2)
line([a3-0.3.*cosd(240) a3+0.3.*cosd(240)],[b3-0.3.*sind(240) b3+0.3.*sind(240)],'color','k','linewidth',2)
text(a1+0.4,b1,'0\circ')
text(a2+0.2,b2+0.2,'120\circ')
text(a3+0.2,b3+0.2,'240\circ')
handles.hlegend=legend (h2,{['Radius=',num2str(amp0),'mm'],['Radius=',num2str(amp1),'mm'],['Radius=',num2str(amp2),'mm'],...
['Radius=',num2str(amp3),'mm']},'FontName','Arial','FontWeight','bold','Location','NorthEast');

%calculation
syms x y h1 h2 h3 k1 k2 k3 r1 r2 r3
h1=a1;h2=a2;h3=a3;k1=b1;k2=b2;k3=b3;r1=amp1;r2=amp2;r3=amp3;
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
eq2=(x-h2).^2+(y-k2).^2-r2.^2;
eq3=(x-h3).^2+(y-k3).^2-r3.^2;
[x12 y12]=solve(eq1,eq2);[x13 y13]=solve(eq1,eq3);[x23 y23]=solve(eq2,eq3);
x12=sym2poly(x12);x13=sym2poly(x13);x23=sym2poly(x23);
y12=sym2poly(y12);y13=sym2poly(y13);y23=sym2poly(y23);
for i=1:2
    if isreal(x12(i,1))==1
        x12(i,1)=x12(i,1);
    else
        x12(i,1)=nan;
    end
    if isreal(x13(i,1))==1
        x13(i,1)=x13(i,1);
    else
        x13(i,1)=nan;
    end
    if isreal(x23(i,1))
        x23(i,1)=x23(i,1);
    else
        x23(i,1)=nan;
    end
    if isreal(y12(i,1))
        y12(i,1)=y12(i,1);
    else
        y12(i,1)=nan;
    end
    if isreal(y13(i,1))
        y13(i,1)=y13(i,1);
    else
        y13(i,1)=nan;
    end
    if isreal(y23(i,1))
        y23(i,1)=y23(i,1);
    else
        y23(i,1)=nan;
    end
end
c12=[x12 y12];c13=[x13 y13];c23=[x23 y23];
exc12=[];exc13=[];exc23=[];
for i=1:2
if c12(i,:)==[0 0]
    exc12(1,:)=[0 0];
end
if c13(i,:)==[0 0]
    exc13(1,:)=[0 0];
end
if c23(i,:)==[0 0]
    exc23(1,:)=[0 0];
end
end
for i=1:2
if subs(eq1,{x,y},{[c23(i,1)],[c23(i,2)]})<0 | round(subs(eq1,{x,y},{[c23(i,1)],[c23(i,2)]}))==0
    cvert1(i,:)=c23(i,:);
else
    cvert1(i,:)=[0 0];
end
if subs(eq2,{x,y},{[c13(i,1)],[c13(i,2)]})<0 | round(subs(eq2,{x,y},{[c13(i,1)],[c13(i,2)]}))==0
    cvert2(i,:)=c13(i,:);
else
    cvert2(i,:)=[0 0];
end
if subs(eq3,{x,y},{[c12(i,1)],[c12(i,2)]})<0 | round(subs(eq3,{x,y},{[c12(i,1)],[c12(i,2)]})*10)==0
    cvert3(i,:)=c12(i,:);
else
    cvert3(i,:)=[0 0];
end
end
for i=2:-1:1
if cvert1(i,:)==[0 0]
    cvert1(i,:)=[];
end
if cvert2(i,:)==[0 0]
    cvert2(i,:)=[];
end
if cvert3(i,:)==[0 0]
    cvert3(i,:)=[];
end
end
if isempty(cvert1)==1 & isempty(exc23)==0
    cvert1=exc23;
end
if isempty(cvert2)==1 & isempty(exc13)==0
    cvert2=exc13;
end
if isempty(cvert3)==1 & isempty(exc12)==0
    cvert3=exc12;
end
if isempty(cvert1)==1 | isempty(cvert2)==1 | isempty(cvert3)==1 |...
        (isempty(exc23)==0 & isempty(exc13)==0 & isempty(exc12)==0)==1
%calculation12
px=(a1+a2)/2;py=(b1+b2)/2;
if amp1~=amp2
if amp1>amp2
    bigx=a1;bigy=b1;smallx=a2;smally=b2;rbig=amp1;rsmall=amp2;
elseif amp2>amp1
    bigx=a2;bigy=b2;smallx=a1;smally=b1;rbig=amp2;rsmall=amp1;
end
[xang ra]=cart2pol(bigx-px,bigy-py);
syms x y h1 h2 k1 k2 r1 r2 x1 y1 x2 y2 xp1 xp2 yp1 yp2
h1=px;h2=bigx;k1=py;k2=bigy;r1=ra;r2=(rbig-rsmall);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
eq2=(x-h2).^2+(y-k2).^2-r2.^2;
[x12 y12]=solve(eq1,eq2);
x12=sym2poly(x12);
y12=sym2poly(y12);
for i=1:2
    [xang rad(i)]=cart2pol(x12(i,1),y12(i,1));
end
if rad(1)>rad(2)
    m=[x12(1,1) y12(1,1)];
else
    m=[x12(2,1) y12(2,1)];
end
h1=bigx;k1=bigy;r1=rbig;x1=bigx;y1=bigy;x2=m(1,1);y2=m(1,2);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coy=((y2-y1)*(x-x1)/(x2-x1))+y1;
xn=solve(subs(eq1,y,coy));
yn=subs(coy,x,xn);
xb=sym2poly(xn);
yb=sym2poly(yn);
for i=1:2
    [xang(i) rad]=cart2pol(xb(i,1),yb(i,1));
end
if bigx==a1 & bigy==b1
if xang(1)>xang(2)
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
elseif bigx==a2 & bigy==b2
if abs(xang(1))<abs(xang(2))
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
end
h1=smallx;k1=smally;r1=rsmall;xp1=bigx;yp1=bigy;xp2=m(1,1);yp2=m(1,2);x1=smallx;y1=smally;
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((yp2-yp1)*(x-x1)/(xp2-xp1))+y1;
xs=solve(subs(eq1,y,coys));
ys=subs(coys,x,xs);
xs=sym2poly(xs);
ys=sym2poly(ys);
for i=1:2
    [xang(i) rad]=cart2pol(xs(i,1),ys(i,1));
end
if smallx==a1 & smally==b1
if xang(1)>xang(2)
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
elseif smallx==a2 & smally==b2
if abs(xang(1))<abs(xang(2))
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
end
x1=ms(1,1);y1=ms(1,2);x2=mb(1,1);y2=mb(1,2);
tan12=y-y1-((x-x1)*(y2-y1)/(x2-x1));
elseif amp1==amp2
h1=a1;k1=b1;r1=amp1;x1=a1;y1=b1;x2=xc1(61);y2=yc1(61);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((y2-y1)*(x-x1)/(x2-x1))+y1;
excx1=solve(subs(eq1,y,coys));
excy1=subs(coys,x,excx1);
excx1=sym2poly(excx1);
excy1=sym2poly(excy1);
for i=1:2
    [xang rad(i)]=cart2pol(excx1(i,1),excy1(i,1));
end
if rad(1)>rad(2)
    excm1=[excx1(1,1) excy1(1,1)];
else
    excm1=[excx1(2,1) excy1(2,1)];
end
h1=a2;k1=b2;r1=amp2;x1=a2;y1=b2;x2=xc2(61);y2=yc2(61);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((y2-y1)*(x-x1)/(x2-x1))+y1;
excx2=solve(subs(eq1,y,coys));
excy2=subs(coys,x,excx2);
excx2=sym2poly(excx2);
excy2=sym2poly(excy2);
for i=1:2
    [xang rad(i)]=cart2pol(excx2(i,1),excy2(i,1));
end
if rad(1)>rad(2)
    excm2=[excx2(1,1) excy2(1,1)];
else
    excm2=[excx2(2,1) excy2(2,1)];
end
x1=excm1(1,1);y1=excm1(1,2);x2=excm2(1,1);y2=excm2(1,2);
tan12=y-y1-((x-x1)*(y2-y1)/(x2-x1));
end
%calculation13
px=(a1+a3)/2;py=(b1+b3)/2;
if amp1~=amp3
if amp1>amp3
    bigx=a1;bigy=b1;smallx=a3;smally=b3;rbig=amp1;rsmall=amp3;
elseif amp3>amp1
    bigx=a3;bigy=b3;smallx=a1;smally=b1;rbig=amp3;rsmall=amp1;
end
[xang ra]=cart2pol(bigx-px,bigy-py);
syms x y h1 h2 k1 k2 r1 r2 x1 y1 x2 y2 xp1 xp2 yp1 yp2
h1=px;h2=bigx;k1=py;k2=bigy;r1=ra;r2=(rbig-rsmall);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
eq2=(x-h2).^2+(y-k2).^2-r2.^2;
[x12 y12]=solve(eq1,eq2);
x12=sym2poly(x12);
y12=sym2poly(y12);
for i=1:2
    [xang rad(i)]=cart2pol(x12(i,1),y12(i,1));
end
if rad(1)>rad(2)
    m=[x12(1,1) y12(1,1)];
else
    m=[x12(2,1) y12(2,1)];
end
h1=bigx;k1=bigy;r1=rbig;x1=bigx;y1=bigy;x2=m(1,1);y2=m(1,2);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coy=((y2-y1)*(x-x1)/(x2-x1))+y1;
xn=solve(subs(eq1,y,coy));
yn=subs(coy,x,xn);
xb=sym2poly(xn);
yb=sym2poly(yn);
for i=1:2
    [xang(i) rad]=cart2pol(xb(i,1),yb(i,1));
end
if bigx==a1 & bigy==b1
if xang(1)<xang(2)
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
elseif bigx==a3 & bigy==b3
if abs(xang(1))<abs(xang(2))
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
end
h1=smallx;k1=smally;r1=rsmall;xp1=bigx;yp1=bigy;xp2=m(1,1);yp2=m(1,2);x1=smallx;y1=smally;
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((yp2-yp1)*(x-x1)/(xp2-xp1))+y1;
xs=solve(subs(eq1,y,coys));
ys=subs(coys,x,xs);
xs=sym2poly(xs);
ys=sym2poly(ys);
for i=1:2
    [xang(i) rad]=cart2pol(xs(i,1),ys(i,1));
end
if smallx==a1 & smally==b1
if xang(1)<xang(2)
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
elseif smallx==a3 & smally==b3
if abs(xang(1))<abs(xang(2))
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
end
x1=ms(1,1);y1=ms(1,2);x2=mb(1,1);y2=mb(1,2);
tan13=y-y1-((x-x1)*(y2-y1)/(x2-x1));
elseif amp1==amp3
h1=a1;k1=b1;r1=amp1;x1=a1;y1=b1;x2=xc1(301);y2=yc1(301);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((y2-y1)*(x-x1)/(x2-x1))+y1;
excx1=solve(subs(eq1,y,coys));
excy1=subs(coys,x,excx1);
excx1=sym2poly(excx1);
excy1=sym2poly(excy1);
for i=1:2
    [xang rad(i)]=cart2pol(excx1(i,1),excy1(i,1));
end
if rad(1)>rad(2)
    excm1=[excx1(1,1) excy1(1,1)];
else
    excm1=[excx1(2,1) excy1(2,1)];
end
h1=a3;k1=b3;r1=amp3;x1=a3;y1=b3;x2=xc3(301);y2=yc3(301);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((y2-y1)*(x-x1)/(x2-x1))+y1;
excx3=solve(subs(eq1,y,coys));
excy3=subs(coys,x,excx3);
excx3=sym2poly(excx3);
excy3=sym2poly(excy3);
for i=1:2
    [xang rad(i)]=cart2pol(excx3(i,1),excy3(i,1));
end
if rad(1)>rad(2)
    excm3=[excx3(1,1) excy3(1,1)];
else
    excm3=[excx3(2,1) excy3(2,1)];
end
x1=excm1(1,1);y1=excm1(1,2);x2=excm3(1,1);y2=excm3(1,2);
tan13=y-y1-((x-x1)*(y2-y1)/(x2-x1));
end
%calculation23
px=(a2+a3)/2;py=(b2+b3)/2;
if amp2~=amp3
if amp2>amp3
    bigx=a2;bigy=b2;smallx=a3;smally=b3;rbig=amp2;rsmall=amp3;
elseif amp3>amp2
    bigx=a3;bigy=b3;smallx=a2;smally=b2;rbig=amp3;rsmall=amp2;
end
[xang ra]=cart2pol(bigx-px,bigy-py);
syms x y h1 h2 k1 k2 r1 r2 x1 y1 x2 y2 xp1 xp2 yp1 yp2
h1=px;h2=bigx;k1=py;k2=bigy;r1=ra;r2=(rbig-rsmall);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
eq2=(x-h2).^2+(y-k2).^2-r2.^2;
[x12 y12]=solve(eq1,eq2);
x12=sym2poly(x12);
y12=sym2poly(y12);
for i=1:2
    [xang rad(i)]=cart2pol(x12(i,1),y12(i,1));
end
if rad(1)>rad(2)
    m=[x12(1,1) y12(1,1)];
else
    m=[x12(2,1) y12(2,1)];
end
h1=bigx;k1=bigy;r1=rbig;x1=bigx;y1=bigy;x2=m(1,1);y2=m(1,2);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coy=((y2-y1)*(x-x1)/(x2-x1))+y1;
xn=solve(subs(eq1,y,coy));
yn=subs(coy,x,xn);
xb=sym2poly(xn);
yb=sym2poly(yn);
for i=1:2
    [xang(i) rad]=cart2pol(xb(i,1),yb(i,1));
end
if bigx==a2 & bigy==b2
if abs(xang(1))>abs(xang(2))
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
elseif bigx==a3 & bigy==b3
if abs(xang(1))>abs(xang(2))
    mb=[xb(1,1) yb(1,1)];
else
    mb=[xb(2,1) yb(2,1)];
end
end
h1=smallx;k1=smally;r1=rsmall;xp1=bigx;yp1=bigy;xp2=m(1,1);yp2=m(1,2);x1=smallx;y1=smally;
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=((yp2-yp1)*(x-x1)/(xp2-xp1))+y1;
xs=solve(subs(eq1,y,coys));
ys=subs(coys,x,xs);
xs=sym2poly(xs);
ys=sym2poly(ys);
for i=1:2
    [xang(i) rad]=cart2pol(xs(i,1),ys(i,1));
end
if smallx==a2 & smally==b2
if abs(xang(1))>abs(xang(2))
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
elseif smallx==a3 & smally==b3
if abs(xang(1))>abs(xang(2))
    ms=[xs(1,1) ys(1,1)];
else
    ms=[xs(2,1) ys(2,1)];
end
end
x1=ms(1,1);y1=ms(1,2);x2=mb(1,1);y2=mb(1,2);
tan23=y-y1-((x-x1)*(y2-y1)/(x2-x1));
elseif amp2==amp3
h1=a2;k1=b2;r1=amp2;x1=a2;y1=b2;x2=xc2(181);y2=yc2(181);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=y1;
excx2=solve(subs(eq1,y,coys));
excy2=subs(coys,x,excx2);
excx2=sym2poly(excx2);
for i=1:2
    [xang rad(i)]=cart2pol(excx2(i,1),excy2(1,1));
end
if rad(1)>rad(2)
    excm2=[excx2(1,1) excy2(1,1)];
else
    excm2=[excx2(2,1) excy2(1,1)];
end
h1=a3;k1=b3;r1=amp3;x1=a3;y1=b3;x2=xc3(181);y2=yc3(181);
eq1=(x-h1).^2+(y-k1).^2-r1.^2;
coys=y1;
excx3=solve(subs(eq1,y,coys));
excy3=subs(coys,x,excx3);
excx3=sym2poly(excx3);
for i=1:2
    [xang rad(i)]=cart2pol(excx3(i,1),excy3(1,1));
end
if rad(1)>rad(2)
    excm3=[excx3(1,1) excy3(1,1)];
else
    excm3=[excx3(2,1) excy3(1,1)];
end
x1=excm2(1,1);
tan23=x-x1;
end
[x1n y1n]=solve(tan12,tan13);[x2n y2n]=solve(tan12,tan23);[x3n y3n]=solve(tan13,tan23);
x1n=sym2poly(x1n);x2n=sym2poly(x2n);x3n=sym2poly(x3n);
y1n=sym2poly(y1n);y2n=sym2poly(y2n);y3n=sym2poly(y3n);
cvert1=[x1n y1n];cvert2=[x2n y2n];cvert3=[x3n y3n];
end
cvert=[cvert1;cvert2;cvert3];
%result
position_of_corrected_mass=[(cvert(1,1)+cvert(2,1)+cvert(3,1))/3 (cvert(1,2)+cvert(2,2)+cvert(3,2))/3];
plot(position_of_corrected_mass(1,1),position_of_corrected_mass(1,2))
line([cvert1(1,1) cvert2(1,1)],[cvert1(1,2) cvert2(1,2)],'color','b','LineWidth',2)
line([cvert1(1,1) cvert3(1,1)],[cvert1(1,2) cvert3(1,2)],'color','b','LineWidth',2)
line([cvert3(1,1) cvert2(1,1)],[cvert3(1,2) cvert2(1,2)],'color','b','LineWidth',2)
line([position_of_corrected_mass(1,1) amp0+amp1+0.35],[position_of_corrected_mass(1,2) 0],'marker','.','color','k')
[ang radi]=cart2pol(position_of_corrected_mass(1,1),position_of_corrected_mass(1,2));
corrected_mass=tmass*amp0/radi;
if isinf(corrected_mass)
    corrected_mass=0;
end
text(amp0+amp1+0.5,0,{'\bfPosition of corrected mass:\rm';['Radius=\bf',num2str(radi)];['\rmAngle=\bf',...
num2str(ang*180/pi),'\circ'];['\rmCorrected mass=\bf',num2str(corrected_mass)]},'EdgeColor',[0 0 0],'FontName','Arial', 'LineWidth',2)
end
guidata(hObject,handles)

% --------------------------------------------------------------------
function save1_Callback(hObject, eventdata, handles)
% hObject    handle to save1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
haxes=handles.haxes;
hlegend1=handles.hlegend;
[file path]=uiputfile('','Save as');
anew=figure;
copyobj(haxes,anew)
set(hlegend1,'location','NorthEastOutside')
copyobj(hlegend1,anew)
saveas(anew,[path file])
set(hlegend1,'location','NorthEast')
close(anew)

Contact us