USEFUL math this time
So suppose you were trying to make the curved-top sleeve of a 14th-15th-century shirt, smock, dress, pourpoint, etc. (And how many of my friends-list aren't doing that this week?) You've got a measurement from the top of the sleeve to the wrist, and a measurement from the armpit to the wrist, and the difference between these measurements is the height (trough to peak, i.e. twice the amplitude) of the curve. You've also got an armscye that the sleeve needs to fit into, which means the length of the curved top (after deducting seam allowances) has to match the length of the armscye (ditto). So, given the width of the fabric and the height of the curve, how long will the curved top be? Even better, given the height of the curve and the length of the armscye, how wide should the sleeve top be?
For simplicity, let's assume the curve is a sine wave. Its amplitude is h/2, and its wavelength is w (the width of the fabric). In computing the length of the curve, we don't care whether the whole thing is raised up, or lowered, or rotated, or any of that, so I'll just say
f(x) = -(h/2) cos(2 π x/w)
To find the length of a curve, you compute the definite integral of sqrt(1 + f'(x)) (check Wikipedia... yes, I remembered that formula right, yay.)
f'(x) = π h/w sin(2 π x/w)
So we need the integral of sqrt(1 + π2 (h2)/(w2) sin2(2 π x/w))
which is almost certainly non-integrable. That's what numeric methods are for. Now, I know the RIGHT ways to compute integrals numerically involve Simpson's rule and stuff like that, but I don't remember any of the details from twenty years ago, so I'll use brute force and do a Monte Carlo integration: generate a gazillion random (x,y) points in a rectangle that encloses the curve in question, and see what fraction of the points are under the curve.
Wait, that's stupid: if I'm computing f(x) anyway in order to tell whether the random (x,y) is below it, why not use the full f(x) information rather than just that one bit?
On testing, this does seem to give me more-accurate answers, slightly faster, for the same number of points.
In fact, it's a little spooky: multiple tests of the same arc-length computation give me EXACTLY the same answer, to 17 places. That can't be right... no, wait, those tests are for a triangular-topped sleeve, whose derivative takes on only two values, and they're negations of one another, so (sqrt (+ 1 (sqr (fprime x)))) is actually a constant. Try it again on a real function, like the sine curve that started this whole thing, and the answers are NOT exactly equal, just close, as one would expect. Whew!
So, I plug in h=4" and w=13" (since I happen to be holding a piece of 13"-wide linen). If the sleeve top were just angled straight lines, the answer would come out 2*sqrt(h2 + w2/4) = 15.26". With the sine curve and the Monte Carlo simulation for 100000 points, it comes out... 15.64". In other words, using a sine curve rather than straight lines makes less than a half-inch difference, which is comparable to the error in cutting and the bias stretch.
So now I know that, and next time I can just use the straight-line approximation.
For simplicity, let's assume the curve is a sine wave. Its amplitude is h/2, and its wavelength is w (the width of the fabric). In computing the length of the curve, we don't care whether the whole thing is raised up, or lowered, or rotated, or any of that, so I'll just say
f(x) = -(h/2) cos(2 π x/w)
To find the length of a curve, you compute the definite integral of sqrt(1 + f'(x)) (check Wikipedia... yes, I remembered that formula right, yay.)
f'(x) = π h/w sin(2 π x/w)
So we need the integral of sqrt(1 + π2 (h2)/(w2) sin2(2 π x/w))
which is almost certainly non-integrable. That's what numeric methods are for. Now, I know the RIGHT ways to compute integrals numerically involve Simpson's rule and stuff like that, but I don't remember any of the details from twenty years ago, so I'll use brute force and do a Monte Carlo integration: generate a gazillion random (x,y) points in a rectangle that encloses the curve in question, and see what fraction of the points are under the curve.
(define (points-below f xmin xmax ymin ymax points-left answer)
(if (<= points-left 0)
answer
(local [(define x (+ xmin (* (- xmax xmin) (random))))
(define y (+ ymin (* (- ymax ymin) (random))))]
(if (< y (f x))
(points-below f xmin xmax ymin ymax (- points-left 1) (+ 1 answer))
(points-below f xmin xmax ymin ymax (- points-left 1) answer))))
)
(define (integrate f xmin xmax ymin ymax points)
(* (- xmax xmin) (- ymax ymin) (/ (points-below f xmin xmax ymin ymax points 0) points))
)
(define (arc-length fprime xmin xmax ymax points)
(integrate (lambda (x) (sqrt (+ 1 (sqr (fprime x)))))
xmin xmax 0 (+ 1 ymax) points))
Wait, that's stupid: if I'm computing f(x) anyway in order to tell whether the random (x,y) is below it, why not use the full f(x) information rather than just that one bit?
(define (add-f-values f xmin xmax points-left answer)
(if (<= points-left 0)
answer
(local [(define x (+ xmin (* (- xmax xmin) (random))))]
(add-f-values f xmin xmax (- points-left 1) (+ (f x) answer)))))
(define (integrate f xmin xmax ymin ymax points)
(* (- xmax xmin) (/ (add-f-values f xmin xmax points 0) points)))
On testing, this does seem to give me more-accurate answers, slightly faster, for the same number of points.
In fact, it's a little spooky: multiple tests of the same arc-length computation give me EXACTLY the same answer, to 17 places. That can't be right... no, wait, those tests are for a triangular-topped sleeve, whose derivative takes on only two values, and they're negations of one another, so (sqrt (+ 1 (sqr (fprime x)))) is actually a constant. Try it again on a real function, like the sine curve that started this whole thing, and the answers are NOT exactly equal, just close, as one would expect. Whew!
So, I plug in h=4" and w=13" (since I happen to be holding a piece of 13"-wide linen). If the sleeve top were just angled straight lines, the answer would come out 2*sqrt(h2 + w2/4) = 15.26". With the sine curve and the Monte Carlo simulation for 100000 points, it comes out... 15.64". In other words, using a sine curve rather than straight lines makes less than a half-inch difference, which is comparable to the error in cutting and the bias stretch.
So now I know that, and next time I can just use the straight-line approximation.

no subject