Is there an elegant method to separate a 2-dimensional vector into a diagonal vector and a vector following either the x or y axis?

25 Views Asked by At

Hello dear Mathematics users,

Is there an elegant method for separating a vector into two vectors, one diagonal and the other collinear to either the x or the y axis, so that the sum of their magnitudes would be as low as possible? Eg, separating (3,2) to (2,2) and (1,0)?

Context: I'm working on a personal programming project. I'm sure I could achieve this with a quick and dirty code kludge, but that would feel... dissatisfying. I'm trying to avoid conditional logic for optimization purposes.