#! /usr/bin/gawk -f
# Usage: radial-squeeze [ -v x=COL ] [ -v y=COL ] [ -v noise VALUE ] < FILE
#
# Performs a radial logarithmic contraction of the plane
# Reads FILE with two numbers x, y per line.
# The fields numbers of x and y can be given as shown; defaults are 1 and 2.
# If "-v noise" is given, perturbs them with random noise of that amplitude.
# Outputs two numbers a*x, a*y per line
# where a is log(r^2+1)/2r
BEGIN {
if (x == "") x = 1;
if (y == "") y = 2;
if (noise == "") noise = 0;
}
/^#/ { print; next; }
/./ {
vx = $(x) + noise*(2*rand() - 1);
vy = $(y) + noise*(2*rand() - 1);
r = sqrt(vx*vx + vy*vy);
s = log(r*r + 1)/2;
if (r == 0)
{ print 0, 0; }
else
{ print (vx/r)*s, (vy/r)*s; }
next;
}
/^$/ { next; }