# Orthogonal projection onto an affine subspace

If we want to find the distance from a vector $x$ to a subspace $S$, we take $\| (I-P_S) x\|$, where $P_S$ is the orthogonal projection onto the subspace $S$. Obviously we could do the same thing for an affine subspace $A$, although $P_A$ would now not be a linear operator. But how can we find $P_A$? Or perhaps we need not go to the trouble of finding $P_A$ in order to calculate the distance from a point $x$ to $A$?

Once we find $(I - P_A)(0)$, whose norm is the distance from the affine subspace to the origin, we're good, because then if $v = (I - P_A)(0)$, we have $\{a - v \mid a\in A\}$ is a subspace, and the distance from $x$ to $A$ is the distance from $x-v$ to $\{a - v \mid a\in A\}$. But is there an easier way?

1. What is the easiest way to describe a projection onto an affine subspace?
2. What is the easiest way to find the distance from a point to an affine subspace?

I ask because I am afraid this will come up on some exams in the fall, so I am biased toward "calculation" type answers...

(I apologize if this is a repeat... I didn't find this on the site)

• Concretely, if $A=a+S$ is your afffine subspace, and if $p_S$ is the projection onto the linear subspace $S$, then $p_Ax=a+p_S(x-a)$. And the distance from $x$ to $A$ is the distance from $x-a$ to $S$, that is $\|(I-p_S)(x-a)\|$. There is no easier way because that's just an immediate extension of what you do when $a=0$. Jul 26, 2013 at 19:42
• Note that what I said is true for any choice of $a\in A$. So you don't need to bother with the distance from $A$ to the origin. Just pick any $a\in A$. Jul 26, 2013 at 19:53
• I don't have enough reputation to comment, but I just posted how to actually compute the projection matrix (since that information sometimes gets buried) in the answer to a duplicate question: math.stackexchange.com/questions/619879/…
– yig
Jan 25, 2018 at 17:12

Given an orthogonal projection $P_S$ onto a subspace $S$, the orthogonal projection onto the affine subspace $a + S$ is $$P_A(x) = a + P_S(x-a).$$