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
> 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:
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.
> 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.
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.