Help understanding this example of a linear operator which rotates each vector $v$ about the z-axis by an angle $\theta$ 
Let $T: \mathbb{R}^{3} \to \mathbb{R}^{3}$ be the following linear operator, which rotates each vector $v$ about the $z$-axis by an angle $\theta$: $T(x,y,z) = (x\cos\theta-y\sin\theta, x\sin\theta+y\cos\theta, z)$.
Observe that each vector $w = (a,b,0)$ in the $xy$-plane $W$ remains in $W$ under the mapping $T$; hence, $W$ is $T$-invariant. Observe also that the $z$-axis $U$ is invariant under $T$. Furthermore, the restriction of $T$ to $W$ rotates each vector about the origin $0$, and the restriction of $T$ to $U$ is the identity mapping of $U$.

Could someone please help explain this example to me?
First, why is the domain $\mathbb{R}^{3}$? If I had just seen this linear operator, I would have written $T: \mathbb{R}^{4} \to \mathbb{R}^{3}$ with $T(x,y,z,\theta) = (x\cos\theta-y\sin\theta, x\sin\theta+y\cos\theta, z)$... is that incorrect? Would $\theta$ just be given "on the side" somewhere?
Second, where do the formulas $x\cos\theta - y\sin\theta$ and $x\sin\theta+y\cos\theta$ come from? Are they unique? At the moment I am not looking at them thinking "oh right, that's a rotation of angle $\theta$...".
Finally, in general with regard to invariance, is that the same as saying the operator is an endomorphism when it comes to a subspace?
Thank you for any help!
 A: First, the number $\theta$ is a parameter which you should think of as some number fixed for all time (or, it's "on the side" as you put it).  The function from $\mathbb{R}^4\rightarrow\mathbb{R}^3$ you described is not linear in $\theta$.
Second, the formulas $x\cos\theta - y\sin\theta$ and $x\sin\theta + \cos\theta$ are the standard formulas for rotation by angle $\theta$.  To see this, consider what this means in terms of a basis.  For example, if we're rotating everything by $\theta$, where should the point $(1,0)$ go?  (Draw it out if you're not convinces).  It should go to the point $(\cos\theta,\sin\theta)$.  Plugging in $x = 1$ and $y=0$, the formulas you give agree with that.
Likewise, where should $(0,1)$ go if we rotate by $\theta$?  It should go to $(-\sin\theta, \cos\theta)$ as you can verify by sketching a picture.
Putting these together and using linearity gives the standard rotation equtions you wrote down.
Finally,  given a linear map $T:V\rightarrow V$, a subspace $W\subseteq V$ is invariant under $T$ if $TW\subseteq W$, that is if you plug in a vector in $W$ into $T$ it spits out a vector in $W$.  It's equivalent to saying $T$ restricts to an endomorphism of $W$.
