Projection onto affine-hulls Let $S\subseteq \mathbb{R}^n$ be a set of points. 
Let $L(S):=\{\sum_{i=1}^{k} \lambda_i v_i \mid k>0, v_i\in S, \lambda_i\in\mathbb{R}, \sum_{i=1}^n\lambda_i = 1\}$ be the affine-hull of $S$. Let $x\in\mathbb{R}^n$. 
How would you formally define the projection $P(x, S)$ of $x$ onto $L(S)$? 
Since $L(S)$ is a translation of a vector linear space $W$, say $p+W$, then if $P_W$ is the projection matrix onto $W$, I would say that $p+P_W(x-p)$ is the projection onto the affine-hull... but is this correct and the standard way to go?
I'm not really satisfied by this definition because the relation between $L(S)$ and $x$ is shadowed by $p,W \!$...
 A: I would define the projection on a affine subspace of an euclidean space as the map which sends any point to the closest one in the affine subspace.
In your case the subspace is defined as the smallest affine subspace containing a given set of points $v_1,\dots, v_k$. Let $w_j = v_{j}-v_k$ for $j=1,\dots, k-1$. You should apply the orthonormalization process to the vectors $w_j$ to find an orthonormal base $e_1,\dots, e_n$ such that the space generated by $e_1,\dots,e_m$ is equal to the space generated by $w_1,\dots,w_k$ (of course $m\le k$). In such a base the linear part of the projection is represented in coordinates by $P(x_1,\dots,x_n) = (x_1, \dots, x_m, 0, \dots ,0)$.
A: The projection of a point $x$ onto $L(S)$ is the intersection of $x + W^\bot$ with $L(S)$, where $W$ is the linear part of $L(S)$ and $W^\bot$ is it's orthogonal space, that is, the linear space of vector orthogonal to $W$.
A: I don't know of a computationally more efficient way to project points onto the affine subspace (flat) than what you describe ($p + P_{\textit{null}(W)}( x - p )$).
Given ${W}$ with orthonormal columns, $P_{\textit{null}(W)} = {W} {W}^\top$
and ${I} - P_{\textit{null}(W)}$ are projection matrices onto the nullspace and row-space, respectively. If ${W}$'s columns are linearly independent but not orthonormal, $P_{\textit{null}(W)} = {W} ({W}^\top {W})^{-1} {W}^\top$. If W's columns aren't even linearly independent, I believe you can use the pseudoinverse instead of the inverse.
A couple of other useful properties of projection matrices: Given a projection matrix ${P}$, ${P}^\top={P}={P}{P}$. The eigenvalues of ${P}$ are either 0 or 1. If your linear subspace is defined implicitly by a basis orthogonal to it, it is probably computationally more efficient to get the needed projection matrix via $I - P$.
