% chain.m - calculate chain length
% HJSIII, 04.06.23

% guess center distance
%    CD     P   N2   N3    N
%  3.10  0.25   12   36   50
%  3.20  0.25   10   36   50
%  3.18  0.25   12   28   46
%  3.69  0.25   12   28   50

CD = 3.69;

% pitch and number of teeth
P = 0.25;
N2 = 12;
N3 = 28;

% pitch radii
alpha2 = pi / N2;
r2 = P /2 /sin(alpha2);

alpha3 = pi / N3;
r3 = P /2 /sin(alpha3);

% approximate diameters over chain
od2 = 2 * r2 + P
od3 = 2 * r3 + P

% wrap angles
phi = asin( (r3-r2) / CD );
theta2 = pi - 2*phi;
theta3 = pi + 2*phi;

% segment lengths
s1 = CD * cos(phi);
s2 = N2 * P * theta2 /2 / pi;
s3 = N3 * P * theta3 /2 / pi;

% chain length and number of links
L = 2*s1 + s2 + s3;
N = L / P
