Lesson 3 of 18
Vector Magnitude
Vector Magnitude in 3D
The magnitude (or length) of a vector is:
This is a direct extension of the Pythagorean theorem into three dimensions.
Unit Vectors
A vector with magnitude 1 is called a unit vector. To normalize any vector:
Unit vectors indicate direction only.
Distance Between Points
The distance between and is the magnitude of their difference:
Examples
| Vector | Magnitude |
|---|---|
| (3, 4, 0) | 5 |
| (1, 1, 1) | |
| (2, 2, 1) | 3 |
| (0, 0, 0) | 0 |
Your Task
Implement double vec_length3(double x, double y, double z) that returns the 3D vector magnitude.
Use #include <math.h> and the sqrt function.
TCC compiler loading...
Loading...
Click "Run" to execute your code.