# Last edited on 2021-07-31 15:37:23 by jstolfi from math import hypot, floor def basis_2d_hartley_choose(fxm,fym,iso): # Returns a list of pairs ({fx,fy)} which are # the integer frequency vectors for a 2d Hartley basis # with max absolute frequency {fxm} along the {x} axis and {fym} # along the {y} axis. # # If {iso} is false, includes all frequency vectors with {|fx| <= fxm} # and {|fy| <= fym}. # # If {iso} is true, considers only frequency vectors such that {(fx/fxm,fy/fym)} # is inside or on the unit circle. Beware of roundoff errors; use fractional # {fxm,fym} if necessary to overcome them. nfx = 2*int(floor(fxm)) + 1; nfy = 2*int(floor(fym)) + 1; fr = [] # Frequency vectors. for kfx in range(nfx): fx = kfx - fxm for kfy in range(nfy): fy = kfy - fym ok = (not iso) or (hypot(fx/fxm,fw/fym) <= 1.0) if ok: fr.append((fx,fy)) return fr # ----------------------------------------------------------------------