HomeMath › Vector Calculator

Vector Calculator

Computes, for two vectors in 2D or 3D, their magnitudes, dot product, cross product, the angle between them, unit vectors, the scalar and vector projection of the first onto the second, and their sum and difference.

When to use

You have two vectors with numeric components and need any of the standard products, the angle between them, or the projection of one onto the other.

Do not use when: You need the distance between two points rather than vector products (use distance-3d or distance-2d), or the vectors have more than 3 components.

Formula

a·b = Σ aᵢbᵢ; a×b = (a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁); |a| = √(a·a); cos θ = a·b / (|a|·|b|); proj_b a = (a·b / |b|²)·b; scalar projection = a·b / |b|

The angle is evaluated as atan2(|a×b|, a·b), which equals arccos(a·b / (|a|·|b|)) but keeps full precision for nearly parallel or perpendicular vectors; 'parallel' and 'perpendicular' are reported when sin θ or cos θ is below 10^-9.

Inputs

ParameterTypeUnitRequiredDescription
vector_anumber_listyesComponents of the first vector, 2 or 3 numbers (e.g. 1, 2, 3).
vector_bnumber_listyesComponents of the second vector, with the same number of components as vector_a.

Outputs

OutputTypeUnitDescription
dot_productnumberΣ aᵢ·bᵢ; zero when the vectors are perpendicular.
cross_productnumber_list[a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁]; 2D vectors are treated as 3D with z = 0, so only the third component can be non-zero.
cross_product_magnitudenumber|a|·|b|·sin θ, the area of the parallelogram spanned by a and b.
magnitude_anumberLength of vector a, √(Σ aᵢ²).
magnitude_bnumberLength of vector b.
angle_degreesnumber°arccos(a·b / (|a|·|b|)) in degrees, 0–180.
angle_radiansnumberradThe same angle in radians.
unit_vector_anumber_lista / |a|.
unit_vector_bnumber_listb / |b|.
scalar_projectionnumbera·b / |b| (signed length of a along b).
vector_projectionnumber_list(a·b / |b|²) · b.
sumnumber_listComponent-wise sum.
differencenumber_listComponent-wise difference.
relationshipstring'perpendicular', 'parallel (same direction)', 'parallel (opposite direction)' or 'neither', from the angle.

Example

a = (1, 2, 3), b = (4, 5, 6): {"vector_a":[1,2,3],"vector_b":[4,5,6]}{"dot_product":32,"cross_product":[-3,6,-3],"cross_product_magnitude":7.348469,"magnitude_a":3.741657,"magnitude_b":8.774964,"angle_degrees":12.9332,"unit_vector_a":[0.267261,0.534522,0.801784],"scalar_projection":3.646738,"vector_projection":[1.662338,2.077922,2.493506],"sum":[5,7,9],"difference":[-3,-3,-3],"relationship":"neither"}

a = (3, 4), b = (4, −3): {"vector_a":[3,4],"vector_b":[4,-3]}{"dot_product":0,"cross_product":[0,0,-25],"magnitude_a":5,"magnitude_b":5,"angle_degrees":90,"unit_vector_a":[0.6,0.8],"scalar_projection":0,"vector_projection":[0,0],"relationship":"perpendicular"}

GET https://tttkmbb.com/api/v1/calculate/vector-operations?vector_a=1%2C2%2C3&vector_b=4%2C5%2C6

Machine access

Sources

FAQ

Is the cross product defined in 2D?

Not as a vector; the calculator embeds 2D vectors in the xy-plane and returns (0, 0, a₁b₂ − a₂b₁), whose third component is the signed area of the parallelogram they span.

Why is the angle between 0° and 180°?

The angle from the dot product is the unsigned angle between the directions; 0° means the same direction, 90° perpendicular and 180° opposite.

Related calculators