NB. Script anins.ijs
NB. by Cliff Reiter for the note "CD Labels and more"
NB. Last update, June 5, 2000
NB. 
NB. Typical usage 
NB. target (r_min r_max) AnIns (a_min a_max) insert
NB. where "target" and "insert" are arrays representing an image,
NB. r_min and a_min give minumal radii (as a 0-1 proportion) and 
NB. angle (in radians) that define the annular sector for the 
NB. insertion

AnIns=:2 : 0
:
imsz=.#x.
'r0 r1'=.m.
'a0 a1'=.n.
i2s=.<:@(*&(2%imsz-1))             NB. image coord to seminormal
nr=.(%r0-r1)"_ * 10&o. - r1"_      NB. normalized radius
na=.(%a1-a0)"_ * 12&o. - a0"_      NB. normaized angle
np=.(nr,na)@+@j.&i2s  f.           NB. normalized polar coordinate function
i=.0
z=.i.0,imsz,2}.$x.
while. i<imsz do.
  npc=.(i.imsz) np i
  q=.*./ |: (0&<: *. <:&1)npc
  od=.i{x.
  if. 0<+/q do.
    id=. (<"1 <. 0.5+(<:2{.$y.)*"1 q#npc){y.
    z=.z,id(q#i.imsz)}od
  else.
    z=.z,od
  end.
  i=.>:i
end.
z
)