this can probably be done much more elegantly using matrix multiplication.
this can probably be done much more elegantly using matrix multiplication.