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