fb:porticula NoPaste
estimate.bas - Ellipsenumfangsberechnung
Uploader: | ytwinky |
Datum/Zeit: | 13.06.2011 16:24:41 |
#include "vbcompat.bi"
#define Pi ATan2(0, -1)
#define Real Double
Const Pi2=0.5*Pi, fmt="#######0.00000000", fmp="+#.00000000000000E-00"
Function Factorial(n As Integer) As Real 'Iterative definition of factorial
Var i=0, mul=1.0
For i=2 To n
mul*=i
Next
Return(mul)
End Function
Function uPol(ra As Real, rb As Real) As Real 'Formula s. Wiki..
Var Eps=Sqr(1-rb^2/ra^2)
Var g5=(1/2*3/4*5/6*7/8)^2*Eps^8/7
Var g6=(1/2*3/4*5/6*7/8*9/10)^2*Eps^10/9
Var g7=(1/2*3/4*5/6*7/8*9/10*11/12)^2*Eps^12/11
Return 2*Pi*ra*(1.0-(1/2)^2*Eps^2-(1/2*3/4)^2*Eps^4/3-(1/2*3/4*5/6)^2*Eps^6/5-g5-g6-g7)
End Function
Var i=0, j=0, n=10
Dim As Real a=6378000.0, b=6356752.31424518, h, e, lgth, s, theta, x, y, xlast, ylast, dt, fact1, fact2
Input "Enter the longer length of ellipse(a): "), e
If e<>0 Then a=e
Input "Enter the shorter length of ellipse(b): "), e
If e<>0 Then b=e
Width 90, 35
e=Sqr(1-b^2/a^2)
h=(a-b)^2/((a+b)^2)
Print Format(a, "a=" &Fmt) & Format(b, !"\nb=" &Fmt) &!"\ne=";
Print Format(e, fmp) &!"\nh=";
Print Format(h, fmp)
j=0
Do While j<6
lgth=0
For i=0 To n
theta=Pi2*i/n
x=a*Cos(theta)
y=b*Sin(theta)
If i>0 Then lgth+=Sqr((x-xlast)^2+(y-ylast)^2)
xlast = x
ylast = y
Next
Print "Numerical : " & Format(4*lgth, Fmt) &" (" & n &" segments)"
n*=10
j+=1
Loop
n=10
For j=0 To 5
lgth=0
dt=Pi2/n
For i=0 To n
theta=Pi2*i/n
lgth+=Sqr(1-e^2*Sin(theta)^2)*dt
Next
lgth*=a
Print "Integral : " & Format(4*lgth, Fmt) &" (" & n &" segments)"
n *= 10
Next
If a=b Then Print "Circle circumference : " &(a*Pi2)
Print "Anonymous : " & Format(Pi*Sqr(2*(a*a + b*b)-0.5*(a-b)^2), Fmt)
Print "Hudson : " & Format(0.25*Pi*(a+b)*(3*(1+h/4)+1/(1-h/4)), Fmt)
Print "Ramanujan I : " & Format(Pi*(3*(a+b)-Sqr((a+3*b)*(3*a+b))), Fmt)
Print "Ramanujan II : " & Format(Pi*(a+b)*(1+3*h/(10+Sqr(4-3*h))), Fmt)
s=Log(2.0)/Log(Pi2)
Print "Necat : " &Format((4*((a^s)+(b^s))^(1.0/s)), Fmt) &" (s: " & s &")"
s=IIf(e<0.99, (3*Pi-8)/(8-2*Pi), Log(2.0)/Log(2.0/(4-Pi)))
Print "Cantrell : " & Format((4*(a+b)-2*(4-Pi)*a*b/((a^s)/2+(b^s)/2)^(1.0/s)), Fmt) &" (s: " & s &")"
n=2
Do While n<15
lgth=1
For i=1 To n-1
fact1=Factorial(2*i)
fact2=Factorial(i)
s=fact1
s/=2.0^i*fact2
s/=2.0^i*fact2
s*=s
s*=-e^(2.0*i)/(2.0*i-1)
lgth+=s
Next
lgth*=2*Pi*a
Print "Exact : " & Format(lgth, Fmt) &" (" & n &" terms)"
n+=5
Loop
lgth=uPol(a, b)
Print "Upol = " & Format(lgth, Fmt) &" (7!! terms)"
Print "Eniki..";
GetKey
End