# Component-Wise 3D Vector Projection

I want to define the projection of a vector $$\mathbf{v} \in \mathbb{R}^3$$ onto the line $$\mathbf{r} \in \mathbb{R}^3$$ in terms of the components of $$\mathbf{v} = (v_x, v_y, v_z)$$. In 2D, this looks like the following:

2D component-wise vector projection

The magnitude of the component-wise projection of the velocity vector $$\mathbf{v}$$ onto $$\mathbf{r}$$ is the radial velocity $$v_r$$, and (in 2D) can be expressed as the following:

$$v_r = \text{comp}_{\mathbf{r}} \mathbf{v}_x + \text{comp}_{\mathbf{r}} \mathbf{v}_y = v_x \cos \theta + v_y \sin \theta$$

or in vector form,

$$v_r = \begin{bmatrix} \cos \theta & \sin \theta \end{bmatrix} \begin{bmatrix} v_x \\ v_y \end{bmatrix}$$

The 3D case becomes a bit more complicated, and this is where I haven't been able to understand the geometry of the component-wise projection. In the 3D case, we have the vector $$\mathbf{r}$$ expressed in a form of polar coordinates where the azimuth angle $$\theta$$ is defined in the x-y plane relative to the positive y-axis, and the elevation angle $$\phi$$ is defined in the w-z plane relative to the positive w-axis, where the direction of the w-axis is defined by the direction of the projection of $$\mathbf{r}$$ onto the x-y plane.

3D geometry

The 3D vector $$\mathbf{v}$$ is defined with its origin at the point $$(x,y,x)$$ and has components $$(v_x, v_y, v_z)$$. The magnitude of the component-wise projection of $$\mathbf{v}$$ onto $$\mathbf{r}$$ will be a function of both the azimuth ($$\theta$$) and elevation ($$\phi$$) angles of the form:

$$v_r = \begin{bmatrix} f_1(\theta, \phi) & f_2(\theta, \phi) & f_3(\theta, \phi) \end{bmatrix} \begin{bmatrix} v_x \\ v_y \\v_z \end{bmatrix}$$

• I'm sorry, I find the picture hard to follow: What is the componentwise projection in $2D$? Apr 24 '19 at 16:39
• In blue are the components of $\mathbf{v}$: $\mathbf{v}_x$ and $\mathbf{v}_y$. And in red are the projections of $\mathbf{v}_x$ and $\mathbf{v}_y$ onto $\mathbf{r}$. The negative signs can be ignored. Apr 24 '19 at 16:48
• Though there are two red vectors, their labels are the same: $proj_r(-v_x)$. Could you please clarify which of them is for $x$ and which for $y$? I presume the longer one is for $x$? So the output of the process in 3D should be three vectors along $r$ with magnitudes equal to their projections? Apr 24 '19 at 16:51
• Yes, you're correct. I'm sorry for the error in the graphic. I can fix that. The longer red arrow represents the projection of $\mathbf{v}_x$ onto $\mathbf{r}$ (and is labeled correctly). The shorter red arrow represents the projection of $\mathbf{v}_y$ onto $\mathbf{r}$ (and is currently mislabeled). Apr 24 '19 at 16:54
• Thank you for the feedback. The 2D projection figure has been updated Apr 24 '19 at 17:49

In $$\mathbb R^n$$ in any number of dimensions, with the usual distance function, if you have a line through the origin in the direction of a vector $$\mathbf r,$$ as you have in your first figure, and any other vector $$\mathbf v,$$ the length of the projected vector you get by projecting $$\mathbf v$$ onto the line of $$\mathbf r$$ is just the inner product (aka dot product) $$v_r = \left(\frac1{\lVert\mathbf r\rVert}\mathbf r\right) \cdot v.$$

In general, the vector $$\frac1{\lVert\mathbf r\rVert}\mathbf r$$ is simply a unit vector in the same direction as $$\mathbf r.$$ In two dimensions, with a vector $$\mathbf r$$ at an angle $$\theta$$ from the $$x$$ axis, it happens that the vector on the left side of that inner product is $$\frac1{\lVert\mathbf r\rVert} \mathbf r= \begin{bmatrix} \cos\theta \\ \sin\theta \end{bmatrix},$$ and therefore the inner product is given by the matrix multiplication you showed.

In your three-dimensional case, you can set $$\frac1{\lVert\mathbf r\rVert} \mathbf r= \begin{bmatrix} f_1(\theta, \phi) \\ f_2(\theta, \phi) \\ f_3(\theta, \phi) \end{bmatrix},$$ that is, simply set $$f_1(\theta, \phi),$$ $$f_2(\theta, \phi),$$ and $$f_3(\theta, \phi)$$ to the three coordinates of the unit vector in the direction $$\theta,\phi.$$ You can read these coordinates off your diagram. (They are combinations of trigonometric functions of $$\theta$$ and $$\phi$$ which you've already written; just don't multiply by $$R$$.)

• This doesn't answer the question I posed. Which is to define the magnitude of the projection of $\mathbf{v}$ onto $\mathbf{r}$ in terms of the components of $\mathbf{v}$ ($v_x, v_y, v_z$) and the azimuth and elevation angles, $\theta$ and $\phi$ respectively. Apr 24 '19 at 17:53
• Admittedly I did not just write the formula out explicitly for you. But all the pieces of the solution are either already in your question or in this answer. I think it's better if you recognize them for yourself rather than having it written out as a formula without understanding it. Apr 24 '19 at 17:55
• Do you know what I meant by "set $f_1(\theta, \phi),$ $f_2(\theta, \phi),$ and $f_3(\theta, \phi)$ to the three coordinates of the unit vector in the direction $\theta,\phi.$"? You drew a vector of length $R$ in that direction, you showed the coordinates of that vector, now imagine we set the length to $1.$ Apr 24 '19 at 18:00
• The reason I'm making such a big deal out of finding the coordinates of the unit vector and taking a dot product is that if you're doing a problem like this next week but someone has labeled the angles differently (maybe $\theta$ measured from the $x$ axis and $\phi$ downward from the $z$ axis), the formula with the trig functions will be different, but as long as you can draw a figure like the one you drew in the question you'll be able to write the correct formula. Apr 24 '19 at 18:06
• So, given the coordinate frame defined in the 3D image, we would have: $f_1(\theta, \phi) = \cos \phi \sin \theta$, $f_2(\theta, \phi) = \cos \phi \cos \theta$, and $f_3(\theta, \phi) = \sin \phi$ Apr 24 '19 at 18:42

We want to create vectors along the vector $$\vec r$$ with components being that of the $$x, y, z$$ projections of the vector $$\vec v = (v_x, v_y, v_z)$$.

To create a vector in some direction with some magnitude, we multiply the unit vector along a direction with the magnitude we wish for. So, for example, to create the projection of the $$x$$ value along the direction by $$\vec r$$, we will:

1. Create a unit vector $$\hat r = \vec r / |r|$$, which is the unit vector in the direction along $$\vec r$$
2. Make the new vector $$\vec r_x = v_x \hat r$$, where $$v_x$$ is the x-component of the vector $$v$$.

Similarly, for $$y$$, we can create a vector $$\vec r_y = v_y \hat r$$. And for $$z$$, we can create $$\vec z = v_z \hat r$$.

Since we have the vector $$\vec r$$ in spherical coordinates, we can write the unit vector along the direction $$\vec r$$ in cartesian coordinates as:

$$\hat r = (\cos \phi \sin \theta, \cos \phi \cos \theta, \sin \phi)$$.

So the vectors will be:

1. $$\vec r_x = v_x \hat r = (v_x\cos \phi \sin \theta, v_x \cos \phi \cos \theta,v_x \sin \phi)$$
2. $$\vec r_y = v_y \hat r = (v_y\cos \phi \sin \theta, v_y \cos \phi \cos \theta,v_y \sin \phi)$$
3. $$\vec r_z = v_z \hat r = (v_z\cos \phi \sin \theta, v_z \cos \phi \cos \theta,v_z \sin \phi)$$

If I completely misunderstood the question, please do tell me!

• So are you implying that $\text{proj}_{\mathbf{r}} \mathbf{v} = \vec{r}_x + \vec{r}_y + \vec{r}_z$ ? Apr 24 '19 at 17:33
• I mean, in the picture at least, there were two separate vectors for the 2D case, so I presume you want 3 vectors for the 3D case? The three vectors will be $(\vec r_x, \vec r_y, \vec r_z)$. And to follow the notation from the 2D picture, the function $proj_r(v) = \hat r |v|$ Apr 24 '19 at 17:35
• No, the goal is to define the magnitude of the projection of $\mathbf{v}$ onto $\mathbf{r}$ in terms of the components of $\mathbf{v}$ ($v_x, v_y, v_z$) and the azimuth and elevation angles, $\theta$ and $\phi$ respectively. Apr 24 '19 at 17:55