quad to matrix conversion