Lesson 4 of 18
Scalar Projection
Scalar Projection
The scalar projection of onto answers: "how much of points in the direction of ?"
This is the signed length of the shadow of onto the line through .
Derivation
From the dot product formula:
Dividing by :
Vector Projection
The vector projection (not required here) returns the actual vector:
Examples
| (3,4,0) | (1,0,0) | 3 (just the x-component) |
| (1,1,1) | (0,1,0) | 1 (just the y-component) |
| (3,4,0) | (3,4,0) | $5 = |
Your Task
Implement double scalar_proj(double ax, double ay, double az, double bx, double by, double bz) that returns the scalar projection of onto .
Use #include <math.h> for sqrt.
TCC compiler loading...
Loading...
Click "Run" to execute your code.