Go up one level of abstraction.

My math is bad right now (i'm tired) so the weights are probably off.
Anyway, the idea is solid. It's basically about moving up a level of
abstraction.

So first off, there shouldn't be different average functions for
different number of elements. That's just silly.

Second, instead of doing this:

avg(p1.x, p2.x, p3.x)

lets try and do this:

avg('x', [p1, p2, p3])

i.e. specify the points and the dimension independently. Then we can
shorten our code because the points don't change.

Also, once we do that, we can create a function which gives us the sum
each dimension, so you can say:

ax, ay, az = allavg([p1, p2, p3])

For weighted averages, we should have a set of functions that work the
same way, but also takes a list of weights, i.e.:

ax, ay, az = allwavg([p1, p2, p3], [1, 2, 1])

and boom, we've removed a bunch of very long lines of code.