# How Long is a Piece of String? Clever Dood Needed!

This is a discussion on How Long is a Piece of String? Clever Dood Needed! within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I have a maths problem. My program is rendering a sine wave of the form: y = oy + (ay ...

1. ## How Long is a Piece of String? Clever Dood Needed!

I have a maths problem.

My program is rendering a sine wave of the form:

y = oy + (ay * SIN(ax * x))

So in ASCII art it looks like :

Code:
```y   _
|  / \
|     \_/
|______x```
Here's my problem. I want to calculate the path length of the wave. Furthermore, I want to calculate the path length traversed from starting point (0, 0) to some point on the x axis.

In otherwords, if we draw the axes on the ground using inches as our dimensions. Then laid out a piece of string in the shape of the sine wave. How long does the string need to be to reach a distince x along the x-axis from the origin?

I believe this problem is solvable with cantenary equations, but my maths is upto scratch with these.

Any ideas?

2. my calculus is not so hot anymore but im sure the length of a curve can be found with integration.

3. >im sure the length of a curve can be found with integration

Ahh! I spent the last two weeks wrestling with this. Integration gives the area under the curve, not the length of the curve.

The only way I know how to solve this is numerically. Inefficient, but I know it will work.

4. The length of a curve y=f(x) from x=a to x=b is

§[a,b] (1-f'(x)^2)^0.5 * dx

where § is the integral sign.

So, you need to know the derivative of f(x)

It can be shown if you rewrite y=f(x) in parametric form.

5. Originally posted by Davros
Integration gives the area under the curve, not the length of the curve.
As you can see, integration can be used to perform lots of things.

6. I am suitably impressed!

But still need help. I haven't done any maths for 8 years.

So if my:

f(x) = ay + SIN(ax * X)

then

f'(x) = ay * ax * COS(ax * x) [I think]

I plug this into:

LEN = §[a,b] (1-f'(x)^2)^0.5 * dx

and get :

LEN = §[a,b] ( (1 - (ay * ax * COS(ax * x)))^2)^0.5 * dx

which equals

LEN = §[a,b] (1 - (2 * ay * ax * COS(ax * x)) + (ay^2* ax^2 * COS(ax * x)^2) )^0.5 * dx

So how do I integrate that lot! Which I've probably got wrong anyhow!

7. Originally posted by Davros

So if my:

f(x) = ay + SIN(ax * X)

then

f'(x) = ay * ax * COS(ax * x) [I think]
No.
f'(x) = ax*cos(ax*x)

And I think you misinterpreted my formula:

§[a,b] (1 - (f'(x))^2 ) ^ 0.5 * dx

Arrgg!! I hate typing math using ascii!!
I've attached an image of the expression, I've replaced "ax" with "a" to avoid ambiguousness (I hate spelling that word, btw).

I don't think that integral can be solved using algebraic methods, though.

8. Thanks for that.

If as you say, the integral [probably] cannot be solved with algebraic methods, am I correct in thinking that I need a numerical solution to my problem?

(I'll go way now & do some maths revision.)

9. Originally posted by Davros
If as you say, the integral [probably] cannot be solved with algebraic methods, am I correct in thinking that I need a numerical solution to my problem?
Yes.

10. Actually, im almost certain it can be, when I get home Ill give it a whack (hint: 1 - cos^2 = sin^2)

11. Your arc length formula is wrong..

§[a,b] (1 - (f'(x))^2 ) ^ 0.5 * dx

should be

§[a,b] (1 + (f'(x))^2 ) ^ 0.5 * dx

I am trying to do the problem... not too easy though .

12. darn, cant do it. I was thinking of some sort of substitution, but it just got uglier, or back to where I started. Anyways, there probably isnt an antiderivative of that since it wasnt even in the integral table in my calc book. Oh well, theres always Simpson's Rule

13. Originally posted by SilentStrike
§[a,b] (1 - (f'(x))^2 ) ^ 0.5 * dx

should be

§[a,b] (1 + (f'(x))^2 ) ^ 0.5 * dx
Yes, thanks for the correction.