the two function rtd and dtr go first, above everything.
for the other two lines, just replace your lines in the code with those. where you're calling the polygon command, replace it with that line, and where you're defining angdeg replace that line with mine, then delete the (setq andrad line completely.
then give it a shot.