# What would be the “definitive” formula to calculate chainstay length from sprocket size, chainring size and number of chain links?

How do I calculate the diameter of a chainring from the number of teeth?

So, my question tries to ellaborate over this, considering that, for single speeds, there will always be a certain unique chainlength (for a new drivetrain) given the gear sizes and the number of links in the chain. Also, for vertical dropouts, where chainstay length is fixed, there might be a "magical gear" when you have almost zero chain-slack with the right combination of sprocket teeth number, chainring teeth number, and number of chain links.

For that reason, I plan to write some app (html+javascript) to get this length. There is a program which does exactely that, but it is not possible, as far as I know, to know which formula it uses, or if it is actually correct:

http://eehouse.org/fixin/formfmu.php

Then, I think the following assumptions should be made:

• The chain perimeter is the sum of the distances between the consecutive centerlines of each pin;
• The nominal distance between centerlines, in a new chain, is half an inch, or "exactely" 12.7mm;
• The chain is considered to run a straight line between the tangent points where it touches each gear (sprocket or chainring);
• The chain is considered a regular polygon sector along the circumference of the gears, as pointed by Lantius in his answer to the linked question.

The result would be the answer to the question: "If I wrap a closed chain with N links around a spocket with S teeth and a chainring with C teeth and pull those apart, what would be the distance between the centerlines of the cog and the chainring?"

EDIT: I'm including an "updated" drawing I generated programmatically (it's quite involving!), so it would be easier to analyze the geometry of the problem:

X is the chainstay length, and it is the hypotenuse of the purple triangle, the short cathetus being R-r (known), and the longer cathetus being equal to B (unknown).

EDIT: (added trig formula) The whole length L of the chain (known) is equal to A+B+C+D. Since B = D, then L = 2B + A + C, or, with all the added trig:

The unknown (B) appears in both sides of the equation, and it looks like it cannot be isolated.

(To make matters worse, there are the natural limitations that teeth profile is not always the same between brands, there might be very small variations of link length between different chains even of the same brand (happens to me quite often), how much chainslack is actually necessary is debatable, and so on, but it would be nice to have a "canonical formula" which actually considers the physical nature of the pinion-and-chain engagement and allows us to calculate this, at least theoretically.)

-
I think you're expecting too much. My guess is that at best you can figure the tangents to the two more or less idealized sprockets (which have a diameter slightly larger than the diameter a chain pin would follow if fully engaged between teeth), and you likely have to solve that by successive approximation. And, in any event, you have to deal with chain stretch. – Daniel R Hicks Mar 21 '12 at 2:00
@DanielRHicks I know that, even if one gets to the perfect ideal formula, practical limitations still introduce so much error that just a fair aproximation falls inside this error margin. (but even so, I like the intellectual exercise). Also, I would be considering just new components, so stretch would be zero in this simplified case. – heltonbiker Mar 21 '12 at 2:17
Well, now that I think about it, the formula is not that difficult. The chain describes one side of a quadrilateral with with two adjacent right angles, and the two shorter sides being the radii of the sprockets. Truncate the quadrilateral to a rectangle and the use good ole squaw on the hippo on the remaining triangle to figure the chain stay length. A dash of trig will figure the % of the circumference of the two sprockets occupied by the chain, giving you the total chain length. The hard part would be working backwards from an integral chain length. – Daniel R Hicks Mar 21 '12 at 11:37
(In your diagram above, the trick is that your two vertical lines shouldn't be straight but should describe slight arrows pointing right, to make right angles with the chain.) – Daniel R Hicks Mar 21 '12 at 11:39
He deleted the answer, I believe, because his formula used the chain stay length to find the ideal chain length, rather than using the chain length to find the chain stay length as you request here in your title and before your edits. By the way, if you edit, leave the original info, so people can follow in the future. – zenbike Mar 22 '12 at 13:40