Geometric nightmare

Hello, this is driving me crazy. I am trying to make an elementary geometric calculation, the length of arc of a semicircunference, and I am not getting the M_PI/2 answer. I don't know if it is a problem of precision or an elementary geometry confusion. Thanks!!!

PS: I am getting 1.4637 for the lenght instead of 1.5708

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <math.h>
using namespace std;

double height(double x);

int main(){

    // Length of an arc. We take N divisions of length x_b - x_a and calculate
    // the length by addition of small hypothenuses.

    double x_a, x_b, y_0, y_1, x_0, x_1, L, interval;
    int N;

    N = 1000;

    L = 0;
    x_b = 1.0;
    x_a = 0.0;
    interval = (x_b - x_a) / N;

    cout << "Interval: " << interval << endl;

    for(int i=0;i<N;i++){
        x_0 = x_a + i*interval;
        x_1 = x_0 + interval;
        y_0 = height(x_0);
        y_1 = height(x_1);
        L += sqrt(pow(interval,2) + pow((y_1 - y_0 ), 2) );
    } // for

    cout << "The total length is: " << L;
    return 0;
}

double height(double x){
    return ( cos (x*M_PI/2.0 ) );
}
Last edited on
> the length of arc of a semicircunference, and I am not getting the M_PI/2 answer.
A semi-circumference has a length of r \pi, assuming r=1 you'll notice that the length of the arc is the same as the angle (by definition of radian)
I guess that you want to compute the length of a quart of circumference.

1
2
3
double height(double x){
    return ( cos (x*M_PI/2.0 ) );
}
Notice that x is multiplying the angle. An interpretation would be that you map the segment [0;1] to the arc [0;pi/2]
Then you apply the cosine and call the result `height' (instead of `width')
http://upload.wikimedia.org/wikipedia/commons/f/fe/Sin_Cos_Tan_Cot_unit_circle.svg
Then when you compute the hypotenuse, you use `interval'. I don't see the triangle.

So, maybe that was not your intention. Draw a diagram with what you tried to do.
Thanks for the reply. You are right, I am trying to calculate the lenght of a quarter of circumference, not the half. It was a typo. I am trying to do this:

http://m.dummies.com/how-to/content/how-to-analyze-arc-length.html

The cos just simply calculate the y of each point and the triangle has a side of length delta-y. It has another side of lenght delta-x (interval) and the length of the hypothenuse is near to the length of the small arc subtended. I guess that the problem with such an enormous error (10% of the real value) has to do with the precision. Nearing to x=1, for small intervals there are huge variations of y and in some way the math precision cannot handle this. It is a double problem. If we have big interval, the difference of lenght among hypothenuse and arc is way too big. If I reduce the interval, the arc is better represented but I get the precision problem. So even with big N, still the same answer. It is the only reason I see but still it does not convince me. Notice that the values are close to the expected result. It indicates the reasoning is correct but not the programmatical approach.
Last edited on
> The cos just simply calculate the y of each point
No, look again at the diagram. \cos \theta = \frac{adj}{hyp}
The equation of a unit circle is x^2 + y^2 = 1 where you can get y = \sqrt{ 1-x^2 }


> I guess that the problem with such an enormous error has to do with the precision
http://en.wikipedia.org/wiki/Accuracy_and_precision (see the figures)
It is not a problem of precision, you are pointing to the wrong value.
Ok, it's very embarrasing.

Now I see it. Let's say x = cos (theta).

Taking your y = sqrt(1 - x^2), then y = sqrt(1 - x^2) = sin (theta).

As theta = acos(x)

y = sin( acos(x)).

For a reason I wanted to use trigonometric functions and get confussed about all of this.

I should have used directly sqrt or sin(acos(x)) for the height. Thank you very much. I have tried and got the result: 1.5708 which is the expected one. Thanks a lot.
Topic archived. No new replies allowed.