Derivation of distance between affine subspaces