standarddeviationcalculator.net

Updated Free · runs in your browser

Math

Vector magnitude and direction calculator

Enter a vector's components to get its length and the direction it points: the angle from the positive x-axis and the bearing for 2D vectors, the direction cosines for 3D ones. Switch the first menu to go the other way, from a magnitude and angle back to components.

2 components for a direction angle and bearing, 3 for direction cosines. i, j, k form works too.

Magnitude and direction 5 at 143.13°
Magnitude |v|5
Direction θ (from +x, anticlockwise)143.13°
In radians2.4981
QuadrantQuadrant II
Reference angle36.87°
Bearing (clockwise from north)306.87° = N 53.13° W
Show the working, step by step
  1. Magnitude by Pythagoras.

    |v| = √((−4)² + 3²) = √25 = 5

  2. The point (−4, 3) is in the Quadrant II.

    arctan(y/x) = arctan(3/−4) = −36.87° (reference angle 36.87°)

  3. x is negative, so add 180° to the calculator value of arctan(y/x).

    θ = atan2(3, −4) = 143.13°

  4. For a bearing, measure clockwise from north instead.

    bearing = (90° − 143.13°) mod 360° = 306.87°, i.e. N 53.13° W

Plain arctan(y/x) only returns angles between −90° and 90°, so it gets quadrants II and III wrong. atan2(y, x) uses the signs of both components.

The formulas

|v| = √(x² + y²) 2D θ = atan2(y, x), 0° ≤ θ < 360° bearing = (90° − θ) mod 360° |v| = √(x² + y² + z²) 3D cos α = x/|v|, cos β = y/|v|, cos γ = z/|v|, cos²α + cos²β + cos²γ = 1 x = |v| cos θ, y = |v| sin θ back to components

A worked example

The default vector is ⟨−4, 3⟩: 4 units left and 3 up.

  1. Magnitude: √((−4)² + 3²) = √(16 + 9) = √25 = 5.
  2. Quadrant: x is negative and y positive, so the vector is in quadrant II.
  3. Reference angle: tan⁻¹(3/4) = 36.87°.
  4. Direction: in quadrant II, θ = 180° − 36.87° = 143.13°. A calculator's tan⁻¹(3/−4) gives −36.87°, which points into quadrant IV, the opposite way; adding 180° fixes it.
  5. Bearing: 90° − 143.13° = −53.13°, plus 360° gives 306.87°, or N 53.13° W.

Getting the quadrant right

tan⁻¹ only returns angles between −90° and 90°, so it cannot tell ⟨4, −3⟩ from ⟨−4, 3⟩: both have y/x = −0.75. The fix depends on where the vector points. atan2(y, x), found in every programming language and in Excel as ATAN2(x, y) (note the order), makes these corrections automatically.

SignsQuadrantDirection θ from tan⁻¹(y/x)Example
x > 0, y > 0Itan⁻¹(y/x)⟨3, 3⟩ → 45°
x < 0, y > 0IItan⁻¹(y/x) + 180°⟨−4, 3⟩ → 143.13°
x < 0, y < 0IIItan⁻¹(y/x) + 180°⟨−3, −3⟩ → 225°
x > 0, y < 0IVtan⁻¹(y/x) + 360°⟨3, −4⟩ → 306.87°
x = 0on the y-axis90° if y > 0, 270° if y < 0⟨0, 5⟩ → 90°

Bearings

Navigation, surveying and many physics problems give directions as bearings: clockwise from north, usually as three figures (a bearing of 045° is north-east). Compass (quadrant) bearings name the nearer of north or south first and then turn towards east or west: S 36.87° E means face south and turn 36.87° towards east, a true bearing of 143.13°. Mixing the two conventions up is the usual reason an answer comes out mirrored in the line y = x.

3D vectors: direction cosines

A 3D vector has no single direction angle, so it is described by the angles α, β, γ it makes with the three axes. For ⟨2, −1, 2⟩: |v| = √(4 + 1 + 4) = 3, the direction cosines are 2/3, −1/3 and 2/3, and the angles are α = 48.19°, β = 109.47° and γ = 48.19°. β is over 90° because the y-component is negative. The elevation above the xy-plane is sin⁻¹(2/3) = 41.81°.

Going back to components

Resolving a vector is the reverse: x = |v| cos θ and y = |v| sin θ. A force of 10 N acting at 210° has components ⟨−8.66025, −5⟩, both negative because 210° lies in quadrant III. Given a bearing instead, say 10 N on a bearing of 120°, convert first: θ = 90° − 120° = −30°, or 330°, which gives ⟨8.66025, −5⟩.

Common questions

How do you find the magnitude of a vector?

Square each component, add them and take the square root: |v| = √(x² + y²) in 2D and √(x² + y² + z²) in 3D. For ⟨−4, 3⟩ that is √(16 + 9) = √25 = 5. The signs of the components do not matter, because squaring removes them.

How do you find the direction angle of a vector?

θ = atan2(y, x), measured anticlockwise from the positive x-axis. If you use a calculator's tan⁻¹(y/x) instead, correct for the quadrant: add 180° when x is negative, and add 360° when x is positive and y is negative. For ⟨−4, 3⟩, tan⁻¹(3/−4) = −36.87°, and adding 180° gives the true direction, 143.13°.

What is the difference between a direction angle and a bearing?

A direction angle in maths is measured anticlockwise from east (the +x axis). A bearing is measured clockwise from north. Convert with bearing = 90° − θ (adding 360° if the result is negative). The direction 143.13° is a bearing of 306.87°, which as a compass bearing is N 53.13° W.

What are direction cosines?

For a 3D vector, the cosines of the angles it makes with the x, y and z axes: cos α = x/|v|, cos β = y/|v|, cos γ = z/|v|. They are the components of the unit vector, so their squares always add to 1. For ⟨2, −1, 2⟩, |v| = 3 and the direction cosines are 2/3, −1/3 and 2/3.

How do I get the components from the magnitude and angle?

x = |v| cos θ and y = |v| sin θ, with θ measured from the +x axis. A force of 10 at 210° has components 10 cos 210° = −8.66025 and 10 sin 210° = −5. If the angle is a bearing, convert it first with θ = 90° − bearing; the calculator does this when you choose “Clockwise from north”.