Your task is to implement a function that calculates the orthogonal projection of a vector v onto another vector L. This projection results in the vector on L that is closest to v.
Write a function orthogonal_projection(v, L)
that takes in two lists, v
(the vector to be projected) and L
(the line vector), and returns the orthogonal projection of v
onto L
. The function should output a list representing the projection vector rounded to three decimal places.
Example: v = [3, 4] L = [1, 0] print(orthogonal_projection(v, L)) # Expected Output: # [3.0, 0.0]
Orthogonal projection is a fundamental concept in linear algebra, used to project one vector onto another. The projection of vector v onto a line defined by vector L results in a new vector that lies on L, representing the closest point to v on that line. This can be thought of v's shadow on L if a light was shown directly down on v
To project a vector v onto a non-zero vector L in space, we calculate the scalar projection of v onto the unit vector of L, which represents the magnitude of the projection. The resulting projection vector lies along the direction of L.
For any vector v in Cartesian space, the orthogonal projection onto L is calculated using the formula:
\[ \text{proj}_{L} (v) = \frac{v \cdot L}{L \cdot L} L \]
Where:
The resulting projection vector lies along the direction of L and represents the component of v that is parallel to L.
More generally, the projection of v onto a unit vector \( \hat{L} \) (the normalized version of L) simplifies to:
\[ \text{proj}_{L} (v) = (v \cdot \hat{L}) \hat{L} \]
Orthogonal projection has a wide range of applications across various fields in mathematics, physics, computer science, and engineering. Some of the most common applications include:
def dot(v1, v2): return sum([ax1 * ax2 for ax1, ax2 in zip(v1, v2)]) def scalar_mult(scalar, v): return [scalar * ax for ax in v] def orthogonal_projection(v, L): L_mag_sq = dot(L, L) proj_scalar = dot(v, L) / L_mag_sq proj_v = scalar_mult(proj_scalar, L) return [round(x, 3) for x in proj_v]
There’s no video solution available yet 😔, but you can be the first to submit one at: GitHub link.