Projection onto a subspace problem I want to project a vector in $x-y$ plane to a one dimensional subspace $M$. $M$ is defined as follows:
\begin{equation} 
M = \{(x,y):(x,y)=\alpha(-\cos\theta,\sin\theta), \alpha\in R \}
\end{equation}
I'm going to provide two approaches which should yield the same result.

$1$st approach: Projection matrix $\\$
$P_M = M(M^HM)^{-1}M^H$
where $M = \begin{bmatrix}
-\alpha \cos\theta \\
\alpha \sin\theta
\end{bmatrix}$
which yields $P_M = \begin{bmatrix}
\cos^2\theta & -\sin\theta \cos\theta \\
-\sin\theta \cos\theta & \sin^2\theta
\end{bmatrix}$
$2$nd approach: Direct optimization over $\alpha$
Now, let the point which is defined in $x-y$ plane is $(p_x,p_y)$. We want to minimize the norm of \begin{bmatrix}
p_x + \alpha \cos\theta \\ 
p_y - \alpha \sin\theta
\end{bmatrix}
So,
$\frac{d}{d\alpha}$$
\{\begin{bmatrix}
p_x + \alpha \cos\theta & p_y - \alpha \sin\theta\end{bmatrix}
\begin{bmatrix}
p_x + \alpha \cos\theta \\ 
p_y - \alpha \sin\theta
\end{bmatrix} \} = 0
$
which yields $\alpha = p_y \sin\theta - p_x \cos\theta$.
Hence, $\begin{bmatrix}
-\alpha \cos\theta \\ 
 \alpha \sin\theta
\end{bmatrix} = \begin{bmatrix}
(-p_y \sin\theta + p_x \cos\theta) \cos\theta \\ 
(p_y \sin\theta - p_x \cos\theta) \sin\theta
\end{bmatrix}$ which yields
$P_M$ = \begin{bmatrix}
\cos^2\theta & -\sin\theta \cos\theta \\\\
-\sin\theta \cos\theta & \sin^2 \theta
\end{bmatrix}
There is a sign difference between the two results. I should have been gone wrong somewhere in here but where?
One additional question: If $M = \{(x,y):(x,y)= a_0 + \alpha(-\cos\theta,\sin\theta), \alpha\in \Bbb R \}$ where $a_0$ constant, can I still use the 1st approach?
Edit: I noticed my mistake and corrected it. You can answer only the additional question.
 A: May I propose another method?
The angle between this line and $x$-axis is $-\theta$ measured from positive side of $x$-axis. Hence the projection matrix is
$$R_{-\theta}Proj_{x}R_{\theta}=
\left[\begin{array}.\cos\theta&\sin\theta\\-\sin\theta&\sin\theta\end{array}\right]\left[\begin{array}.1&0\\0&0\end{array}\right]\left[\begin{array}.\cos(-\theta)&\sin(-\theta)\\-\sin(-\theta)&\sin(-\theta)\end{array}\right]=\left[\begin{array}.\;\;\;\cos^2\theta&-\cos\theta\sin\theta\\-\cos\theta\sin\theta&\;\;\;\sin^2\theta\end{array}\right]$$
A: Additional question: you're looking for affine projection.
$M' = \{(x,y):(x,y)= \mathbf{a_0} + \alpha(-\cos\theta,\sin\theta), \alpha\in \Bbb R \}$ is a copy of $M$ that has been translated away from the origin through $\mathbf{a_0}$. Let's say we want to project $\mathbf{v}$ orthogonally to $M'$ to get $\mathbf{p}'$.
We can do this by subtracting $\mathbf{a_0}$ from $\mathbf{v}$ and $\mathbf{p}'$ as well as everything from $M'$ to put everything back into the context of our usual orthogonal projection:
$$P_M (\mathbf{v-a_0})=\mathbf{p'-a_0}$$
Rearranging the equation we get
$$\mathbf{p'}=\mathbf{a_0}+P_M(\mathbf{v-a_0})$$
