% 紙の曲げ変形

L = 10;
n = 21;
h = L/(n-1);
R = 1;

%lx = 7; ly = 0;
lx = 3; ly = 0;

s = (0:n-1)*h;
thetainit = [ones((n-1)/2,1);0;-ones((n-1)/2,1)];

potential_energy = @(theta) potential_energy_param ( theta, n, s, R );
nonlcon = @(theta) nonlcon_param ( theta, n, s, lx, ly );
[ theta, Umin ] = fmincon ( potential_energy, thetainit, [], [], [], [], [], [], nonlcon);

set(0,'defaultAxesFontSize',16);
set(0,'defaultTextFontSize',16);

plot(s,theta);
xlabel('s');
ylabel('\theta(s)');
ylim([-2,2]);
grid on;
filename = strcat(num2str(lx), '-', num2str(ly), '-theta.eps');
saveas(gcf, filename, 'eps');
fprintf("theta(s)\n");
fprintf("一時停止：何かのキーを押してください\n");
pause;

points = DLO_shape( theta, n, s );
plot(points(:,1), points(:,2));
xlabel('x');
ylabel('y');
xlim([0,10]);
ylim([0,5]);
pbaspect([1 1/2 1]);
grid on;
filename = strcat(num2str(lx), '-', num2str(ly), '-xy.eps');
saveas(gcf, filename, 'eps');
fprintf("変形形状\n");
fprintf("一時停止：何かのキーを押してください\n");
pause;
