theta_input = linspace(0, pi/3, 100);
positions = zeros(length(theta_input), 2 * num_sections + 4, 2);
velocities = zeros(length(theta_input) - 1, 2 * num_sections + 4, 2);
accelerations = zeros(length(theta_input) - 2, 2 * num_sections + 4, 2);
for i = 1:length(theta_input)
joints = zeros(2 * num_sections + 4, 2);
joints(2 * j, :) = [joints(2 * j - 1, 1) + L * cos(theta), joints(2 * j - 1, 2) + L * sin(theta)];
joints(2 * j + 1, :) = [joints(2 * j, 1) + L * cos(pi - theta), joints(2 * j, 2) + L * sin(pi - theta)];
joints(2 * j + 2, :) = [joints(2 * j + 1, 1) - L * cos(theta), joints(2 * j + 1, 2) - L * sin(theta)];
positions(i, :, :) = joints;
dt = theta_input(2) - theta_input(1);
for i = 2:length(theta_input)
velocities(i - 1, :, :) = (positions(i, :, :) - positions(i - 1, :, :)) / dt;
for i = 2:size(velocities, 1)
accelerations(i - 1, :, :) = (velocities(i, :, :) - velocities(i - 1, :, :)) / dt;
xlim([-0.5, base_width + 0.5]);
ylim([-0.5, 2 * num_sections + 0.5]);
title('Full Scissors Lift Mechanism Animation');
xlabel('X Position (m)');
ylabel('Y Position (m)');
for i = 1:length(theta_input)
joints = squeeze(positions(i, :, :));
plot(D(1), D(2), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
plot(F(1), F(2), 'ro', 'MarkerSize', 8, 'LineWidth', 2);
plot([joints(2 * j - 1, 1), joints(2 * j, 1)], ...
[joints(2 * j - 1, 2), joints(2 * j, 2)], 'b-', 'LineWidth', 2);
plot([joints(2 * j, 1), joints(2 * j + 1, 1)], ...
[joints(2 * j, 2), joints(2 * j + 1, 2)], 'r-', 'LineWidth', 2);
plot([joints(2 * j + 2, 1), joints(2 * j, 1)], ...
[joints(2 * j + 2, 2), joints(2 * j, 2)], 'k--', 'LineWidth', 1.5);
plot3(theta_input, squeeze(positions(:, 2, 1)), squeeze(positions(:, 2, 2)), 'b-', 'LineWidth', 1.5);
xlabel('Input Angle (rad)');
ylabel('X Position (m)');
zlabel('Y Position (m)');
title('3D Plot of Joint Positions');
plot3(theta_input(1:end-1), squeeze(velocities(:, 2, 1)), squeeze(velocities(:, 2, 2)), 'r-', 'LineWidth', 1.5);
xlabel('Input Angle (rad)');
ylabel('X Velocity (m/s)');
zlabel('Y Velocity (m/s)');
title('3D Plot of Joint Velocities');
plot3(theta_input(1:end-2), squeeze(accelerations(:, 2, 1)), squeeze(accelerations(:, 2, 2)), 'g-', 'LineWidth', 1.5);
xlabel('Input Angle (rad)');
ylabel('X Acceleration (m/s^2)');
zlabel('Y Acceleration (m/s^2)');
title('3D Plot of Joint Accelerations');