#module
#deffunc circle_area double x, double y, double r, \
local x1, local x2, local y1, local y2, local dx, local dy, local px, local py, \
local theta, local phi, local area, local l_area, local r_area
ddim area, 4
if r*r>x*x {
dy=sqrt(r*r-x*x)
y1=y+dy
y2=y-dy
}
if r*r>y*y {
dx=sqrt(r*r-y*y)
x1=x+dx
x2=x-dx
}
if dx>0.0 and dy>0.0 {
px=x1 , 0.0, x2 , 0.0, x1
py=0.0, y1 , 0.0, y2 , 0.0
repeat 5 : theta.cnt=atan(py.cnt-y, px.cnt-x) : loop
repeat 4 : phi.cnt=rad_abs(theta(cnt+1)-theta.cnt) : loop
repeat 4
area.cnt=r*r*(phi.cnt-sin(phi.cnt))/2.0
if cnt\2 {
area.cnt+=absf(py.cnt*px(cnt+1))/2.0
} else {
area.cnt+=absf(px.cnt*py(cnt+1))/2.0
}
loop
} else : if dy>0.0 {
theta=atan(y1-y, 0.0-x)
r_area=r*r*theta+x*dy
l_area=M_PI*r*r-r_area
if y>0.0 {
area=r_area, l_area, 0.0, 0.0
} else {
area=0.0, 0.0, l_area, r_area
}
} else : if dx>0.0 {
theta=atan(x1-x, 0.0-y)
u_area=r*r*theta+y*dx
d_area=M_PI*r*r-u_area
if x>0.0 {
area=u_area, 0.0, 0.0, d_area
} else {
area=0.0, u_area, d_area, 0.0
}
} else {
w_area=M_PI*r*r
if x>0.0 {
if y>0.0 {
area=w_area, 0.0, 0.0, 0.0
} else {
area=0.0, 0.0, 0.0, w_area
}
} else {
if y>0.0 {
area=0.0, w_area, 0.0, 0.0
} else {
area=0.0, 0.0, w_area, 0.0
}
}
}
buf=strf("x=%f y=%f r=%f ", x, y, r)
repeat 4 : buf+=strf(" %f", area.cnt) : loop
mes buf
return
#defcfunc rad_abs double rad_, local rad
rad=rad_
while rad<0.0 : rad+=2.0*M_PI : wend
while rad>=2.0*M_PI : rad-=2.0*M_PI : wend
if rad>M_PI : rad=2.0*M_PI-rad
return rad
#global
circle_area 11, 11, 10
circle_area -11, 11, 10
circle_area -11, -11, 10
circle_area 11, -11, 10
circle_area 11, 4, 10
circle_area -11, 4, 10
circle_area 3, -11, 10
circle_area 3, 11, 10
circle_area 3, 4, 10
I21vZHVsZQojZGVmZnVuYyBjaXJjbGVfYXJlYSBkb3VibGUgeCwgZG91YmxlIHksIGRvdWJsZSByLCBcCglsb2NhbCB4MSwgbG9jYWwgeDIsIGxvY2FsIHkxLCBsb2NhbCB5MiwgbG9jYWwgZHgsIGxvY2FsIGR5LCBsb2NhbCBweCwgbG9jYWwgcHksIFwKCWxvY2FsIHRoZXRhLCBsb2NhbCBwaGksIGxvY2FsIGFyZWEsIGxvY2FsIGxfYXJlYSwgbG9jYWwgcl9hcmVhCgoJZGRpbSBhcmVhLCA0CglpZiByKnI+eCp4IHsKCQlkeT1zcXJ0KHIqci14KngpCgkJeTE9eStkeQoJCXkyPXktZHkKCX0KCWlmIHIqcj55KnkgewoJCWR4PXNxcnQocipyLXkqeSkKCQl4MT14K2R4CgkJeDI9eC1keAoJfQoJaWYgZHg+MC4wIGFuZCBkeT4wLjAgewoJCXB4PXgxICwgMC4wLCB4MiAsIDAuMCwgeDEKCQlweT0wLjAsIHkxICwgMC4wLCB5MiAsIDAuMAoJCXJlcGVhdCA1IDogdGhldGEuY250PWF0YW4ocHkuY250LXksIHB4LmNudC14KSA6IGxvb3AKCQlyZXBlYXQgNCA6IHBoaS5jbnQ9cmFkX2Ficyh0aGV0YShjbnQrMSktdGhldGEuY250KSA6IGxvb3AKCQlyZXBlYXQgNAoJCQlhcmVhLmNudD1yKnIqKHBoaS5jbnQtc2luKHBoaS5jbnQpKS8yLjAKCQkJaWYgY250XDIgewoJCQkJYXJlYS5jbnQrPWFic2YocHkuY250KnB4KGNudCsxKSkvMi4wCgkJCX0gZWxzZSB7CgkJCQlhcmVhLmNudCs9YWJzZihweC5jbnQqcHkoY250KzEpKS8yLjAKCQkJfQoJCWxvb3AKCX0gZWxzZSA6IGlmIGR5PjAuMCB7CgkJdGhldGE9YXRhbih5MS15LCAwLj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