fork download
  1. #module
  2. #deffunc circle_area double x, double y, double r, \
  3. local x1, local x2, local y1, local y2, local dx, local dy, local px, local py, \
  4. local theta, local phi, local area, local l_area, local r_area
  5.  
  6. ddim area, 4
  7. if r*r>x*x {
  8. dy=sqrt(r*r-x*x)
  9. y1=y+dy
  10. y2=y-dy
  11. }
  12. if r*r>y*y {
  13. dx=sqrt(r*r-y*y)
  14. x1=x+dx
  15. x2=x-dx
  16. }
  17. if dx>0.0 and dy>0.0 {
  18. px=x1 , 0.0, x2 , 0.0, x1
  19. py=0.0, y1 , 0.0, y2 , 0.0
  20. repeat 5 : theta.cnt=atan(py.cnt-y, px.cnt-x) : loop
  21. repeat 4 : phi.cnt=rad_abs(theta(cnt+1)-theta.cnt) : loop
  22. repeat 4
  23. area.cnt=r*r*(phi.cnt-sin(phi.cnt))/2.0
  24. if cnt\2 {
  25. area.cnt+=absf(py.cnt*px(cnt+1))/2.0
  26. } else {
  27. area.cnt+=absf(px.cnt*py(cnt+1))/2.0
  28. }
  29. loop
  30. } else : if dy>0.0 {
  31. theta=atan(y1-y, 0.0-x)
  32. r_area=r*r*theta+x*dy
  33. l_area=M_PI*r*r-r_area
  34. if y>0.0 {
  35. area=r_area, l_area, 0.0, 0.0
  36. } else {
  37. area=0.0, 0.0, l_area, r_area
  38. }
  39. } else : if dx>0.0 {
  40. theta=atan(x1-x, 0.0-y)
  41. u_area=r*r*theta+y*dx
  42. d_area=M_PI*r*r-u_area
  43. if x>0.0 {
  44. area=u_area, 0.0, 0.0, d_area
  45. } else {
  46. area=0.0, u_area, d_area, 0.0
  47. }
  48. } else {
  49. w_area=M_PI*r*r
  50. if x>0.0 {
  51. if y>0.0 {
  52. area=w_area, 0.0, 0.0, 0.0
  53. } else {
  54. area=0.0, 0.0, 0.0, w_area
  55. }
  56. } else {
  57. if y>0.0 {
  58. area=0.0, w_area, 0.0, 0.0
  59. } else {
  60. area=0.0, 0.0, w_area, 0.0
  61. }
  62. }
  63. }
  64. buf=strf("x=%f y=%f r=%f ", x, y, r)
  65. repeat 4 : buf+=strf(" %f", area.cnt) : loop
  66. mes buf
  67. return
  68.  
  69.  
  70. #defcfunc rad_abs double rad_, local rad
  71. rad=rad_
  72. while rad<0.0 : rad+=2.0*M_PI : wend
  73. while rad>=2.0*M_PI : rad-=2.0*M_PI : wend
  74. if rad>M_PI : rad=2.0*M_PI-rad
  75. return rad
  76. #global
  77.  
  78. circle_area 11, 11, 10
  79. circle_area -11, 11, 10
  80. circle_area -11, -11, 10
  81. circle_area 11, -11, 10
  82.  
  83. circle_area 11, 4, 10
  84. circle_area -11, 4, 10
  85. circle_area 3, -11, 10
  86. circle_area 3, 11, 10
  87.  
  88. circle_area 3, 4, 10
  89.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty