function StLouisARCH2024    %3/8/2024  3/18/2024
%  By: David R. Hill, Mathematics Dept., Temple Univ.
%      Philadelphia, PA. 19122    Email: dhill001@temple.edu
%
%StLouisARCH picture on which you select points to create
%a parabola on the picture.

%--X and Y coordinates for placement of upper and lower left hand edges of image.
X=[0 0];Y=[-160 160];
%--Read in the image information
figure
%pic=imread('McDonaldarchpicture.jpg');
pic=imread('St_Louis_arch_larger.jpg');
pic2=double(pic)/255; %setting numerical precision
Rpic=pic2(:,:,1);
Gpic=pic2(:,:,2);
Bpic=pic2(:,:,3);
pic3=rot90(Rpic'); %THIS HAS TO DO WITH ROTATION of the figure
pic3(:,:,2)=rot90(Gpic');
pic3(:,:,3)=rot90(Bpic');
xleft=0; %SETTING GRID values
xright=10;
ybot=0;
ytop=10;
x=[xleft xright];
y=[ybot ytop];
axis([x y])
hold on
image(x,y,pic3); %need pic2 for RAINBOW ARCH arch but pic3 for McDonald
                 %and StLouisArch
                 %this has to do with the orientation of the picture

plot(x,[0 0],'k','LineWidth',2)
plot([0 0],y,'k','LineWidth',2)
title('StLouis ARCH')
xlabel({'You can change the size by pulling a corner if you want to.','PRESS ENTER to select at least 3 points with the mouse.','Press Q to stop selecting points.'})
%braces{   } needed
pause
button=1;
xp=[];yp=[];
jj=1;
while button==1;
    [xin,yin,button]=ginput(1);
    if button~='Q' & button~='q'
        xp(jj)=xin;yp(jj)=yin;%<==points
        hold on
        plot(xin,yin,'r+','markersize',15)
        plot(xin,yin,'ro','markersize',15)
        jj=jj+1;
    end
end
%pause
%disp([xp;yp]'); %column of data points
coef=polyfit(xp,yp,2);   %quadratic coefficients generated here
z=min(xp):.01:max(xp);
yz=polyval(coef,z);
plot(z,yz,'b-','linewidth',3)
%title('Your Parabola is shown!')
sg1=sign(coef(1));
sg2=sign(coef(2));
sg3=sign(coef(3));
%eqn=['y = ' num2str(coef(1)) ' x^2 + '  num2str(coef(2)) ' x + ' num2str(coef(3))];

if sg2==1 & sg3==1
    eqn=['y = ' num2str(coef(1)) ' x^2 + '  num2str(coef(2)) ' x + ' num2str(coef(3))];
end
if sg2==-1 & sg3==-1
    eqn=['y = ' num2str(coef(1)) ' x^2 - '  num2str(abs(coef(2))) ' x - ' num2str(abs(coef(3)))];
end
if sg2==1 & sg3==-1
    eqn=['y = ' num2str(coef(1)) ' x^2 + '  num2str(abs(coef(2))) ' x - ' num2str(abs(coef(3)))];
end
if sg2==-1 & sg3==1
    eqn=['y = ' num2str(coef(1)) ' x^2 - '  num2str(abs(coef(2))) ' x - ' num2str(abs(coef(3)))];
end
xlabel(['Your parabola ===>  ' eqn])

end
%return %stops





