Vector calculator
Enter the two components of a flat vector and get its length, heading and unit vector: (3, 4) has a length of 5 and a unit vector of (0.6, 0.8). The angle always lands in the right quadrant. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- X
- 3
- Y
- 4
- Magnitude
- 5
- Angle deg
- 53.1301023542
- Angle rad
- 0.927295218
- Angle deg 0 360
- 53.1301023542
A two-dimensional vector is completely described either by a pair of Cartesian components or by a length and a heading. This vector calculator takes the x component and the y component, computes the Euclidean magnitude as the square root of x squared plus y squared, and recovers the direction angle with the two-argument arctangent atan2 of y and x so the heading lands in the correct quadrant. The response also reports the matching unit vector, a polar-form string, and both the signed and the zero-to-three-hundred-sixty degree readings.
What a 2D vector calculator returns: length, heading, and unit direction
In the plane, a vector is an arrow from the origin to the point whose coordinates are the components x and y. Two numbers completely fix that arrow, but students, engineers, and game code often want a different pair: how long the arrow is, and which way it points. Length is the Euclidean magnitude, the hypotenuse of the right triangle whose legs are the absolute values of x and y, written r equals the square root of x squared plus y squared.
Heading is the direction angle measured from the positive x-axis, counterclockwise when the angle is positive. The one-argument arctangent of y over x is not enough, because it collapses opposite quadrants and fails when x is zero. The two-argument function atan2 of y and x inspects both signs, so a vector in the second quadrant is not mistaken for one in the fourth, and a pure vertical vector receives plus or minus ninety degrees.
Dividing each component by the magnitude produces the unit vector, the same direction with length one, which is the pair of direction cosines used in lighting, steering, and force resolution. This landing packages those three ideas as one contract: magnitude, signed and wrapped angles, unit components, a polar-form string of the shape r angle theta degrees, and a quadrant or axis label. Dedicated magnitude-only tools that accept an n-dimensional array, and dedicated direction-angle pages that lead with atan2, answer different search queries.
The query here is the generic vector calculator: components in, polar form out.
What to enter and how it is calculated
Computation is a short, fully deterministic path. The magnitude is the Euclidean hypotenuse of x and y. Otherwise the angle in radians is atan2 of y and x, the degree form multiplies by one hundred eighty over pi, and a second degree field wraps the signed result into the half-open interval from zero to three hundred sixty.
Unit components are x over r and y over r. Example: x equals three and y equals four is the classic three-four-five triangle, so the magnitude is five, the heading is about fifty-three point one three degrees, and the unit vector is zero point six and zero point eight. Example: x equals negative five and y equals twelve is a five-twelve-thirteen triangle in the second quadrant.
There is no third component, no spherical pair of angles, and no automatic conversion of the components themselves from feet into metres; callers choose one shared Cartesian frame.
Where a vector calculator earns its keep in study, design, and tests
Classrooms meet this conversion the week polar form is introduced: a textbook gives the components of a force, a displacement, or a velocity and asks for the magnitude and the angle from the positive x-axis. One call returns both quantities plus the unit vector, so a learner can check a full polar-form answer key without flipping a quadrant sign by hand.
Game developers and robotics hobbyists recover the heading of a velocity or aim vector on a 2D plane; converting through atan2 without hand-rolled quadrant logic avoids the classic bug where a character that faces left is reported as facing right. Physics notebooks resolve a force into length and direction before projecting it onto an axis. On this page the work runs entirely in the browser.
Pair this landing with a dedicated n-dimensional magnitude tool when the vector is not planar, with a direction-angle page when the only unknown is the heading, and with an angle converter when results must appear in gradians or turns.
What you can do with it
Homework polar-form checks
Convert textbook components into magnitude, direction angle, and unit vector, and confirm that the zero vector fails instead of inventing a fake 0° heading.
Game headings and aim vectors
Recover the on-plane heading and unit direction of a velocity or aim vector from vx and vy with correct quadrants for left, down, and diagonal motion.
FAQ
What does the vector calculator cost?
It is free in your browser on this page.
How do you find the magnitude and direction of a 2D vector?
Magnitude is r = √(x² + y²). Direction is θ = atan2(y, x) from the positive x-axis. The response includes degrees, radians, a [0, 360) wrap, the unit vector, and a polar-form string.
Why is the zero vector rejected?
When both components are zero the length is zero and the arrow does not point anywhere, so a direction angle and a unit vector are undefined.
Is this the same as a vector-magnitude or direction-angle calculator?
No. A magnitude calculator answers n-dimensional length. A direction-angle tool leads with the heading alone. This vector calculator returns polar form from two planar components: length, angle, and unit direction together.
How do I find the unit vector of a 2D vector?
Divide each component by the length. The vector (3, 4) has a length of 5, so its unit vector is (0.6, 0.8): the same direction, but with a length of exactly one.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/vector \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x":3,"y":4}'const res = await fetch("https://api.kit.forhosting.com/math/vector", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x": 3,
"y": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/vector",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x": 3,
"y": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/vector", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x":3,"y":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x":3,"y":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/vector", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x": 3,
"y": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.vector",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Any component that is not a finite number fails with invalid_input, and the zero vector is rejected because it has no direction.
Input contract, formulas, and what invalid_input means
POST a JSON body with two required finite numbers: x, the horizontal component, and y, the vertical component. Each field may arrive as a JSON number or as a numeric string. When the canonical name is omitted, aliases vx and x_component map to x, and aliases vy and y_component map to y. Missing fields, empty strings, non-numeric text, NaN, and Infinity all fail with invalid_input that names the failing field, and those failures are not billed. If that length is effectively zero the request fails, because a displacement of length zero does not point anywhere and a unit vector cannot be formed.
Where a vector calculator earns its keep in study, design, and tests
Developers wire the API into grading oracles and continuous-integration assertions so known pairs such as three and four stay pinned at magnitude five. Through the API each successful lookup costs $0.002; failed validation is not charged, and nothing is stored after the response returns.
Integration use cases
Deterministic geometry fixtures
Generate reproducible polar-form answers for unit tests, contest validators, and CI assertions without re-implementing atan2 edge cases.
Technical questions
What happens if x or y is not a finite number?
Missing values, empty strings, non-numeric text, NaN, and Infinity fail with invalid_input naming the field. Those requests are not billed.