Line equation from two points
Give two points and get the line through them: (0, 0) and (2, 4) give y equals 2x, which is 2x minus y equals 0 in standard form, with slope and intercept shown. Vertical and horizontal lines are flagged. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- X1
- 0
- Y1
- 0
- X2
- 2
- Y2
- 4
- Slope
- 2
- Intercept
- 0
- Slope intercept
- y = 2x
- Standard form
- 2x - y = 0
Given two distinct points on the Cartesian plane, exactly one straight line passes through both of them. This calculator accepts x1, y1, x2, and y2 as finite numbers, validates every coordinate, rejects coincident points, and returns the slope-intercept form y equals m x plus b when the line is non-vertical, together with the standard form A x plus B y plus C equals zero, the numeric slope and intercept when defined, the coefficient triple, and flags for vertical and horizontal lines.
How two points determine slope-intercept and standard forms
Label the first point as (x1, y1) and the second as (x2, y2). When the x-coordinates differ, the slope m is the rise over run: (y2 minus y1) divided by (x2 minus x1). The y-intercept b follows from the point-slope relation: b equals y1 minus m times x1, so the slope-intercept equation is y equals m x plus b.
When the x-coordinates are equal and the y-coordinates differ, the line is vertical: slope and intercept are undefined, slope-intercept form is omitted, and the equation is x equals that common x-value. Independently of orientation, the standard (general) form can always be written as A x plus B y plus C equals zero using A equals y1 minus y2, B equals x2 minus x1, and C equals x1 y2 minus x2 y1.
Multiplying A, B, and C by the same non-zero constant yields an equivalent equation; this service normalizes the sign so that A is non-negative (and B non-negative when A is zero) and reduces integer coefficients by their greatest common divisor when all three are whole numbers. Horizontal lines have slope zero and standard form proportional to y minus the constant height.
Classic classroom checks include the line through (0, 0) and (1, 1), which is y equals x or x minus y equals zero, and the line through (1, 2) and (3, 6), which is y equals 2x. Because the path uses only subtraction, multiplication, division, and a small amount of formatting, it is deterministic, O(1), and free of iterative solvers or symbolic libraries.
Where line equations from two points show up in real work
Secondary-school and college analytic geometry courses constantly ask students to write the equation of the line through two plotted points in both slope-intercept and standard form; a trusted calculator with a strict coincident-point check speeds homework grading and removes spreadsheet mistakes where someone divides by a zero run or forgets to simplify coefficients. Game, graphics, and CAD tutorials often store control points as pairs of screen or world coordinates and need a closed line equation for clipping, snap constraints, or debug overlays without building a full computational-geometry stack.
If you later need the distance between the same two points, a least-squares fit through many points, or a polar form, treat those as separate search intents rather than overloading this two-point line-equation landing.
What you can do with it
Homework and exam checks
Convert two plotted points into slope-intercept and standard form, and reject coincident points with a clear error.
FAQ
What if a coordinate is not a number?
Missing fields, empty strings, non-numeric text, NaN, and Infinity are all rejected.
What does it cost?
The browser tool is free and runs locally.
What happens when the line is vertical?
If both points share the same x, the slope and the intercept are undefined, so no slope-intercept form is given. The equation is x equals that shared value, and the standard form is still returned as usual.
What if I enter the same point twice?
The calculation stops with a clear message. Infinitely many lines pass through a single point, so a unique line needs two distinct points rather than a silent guess or an arbitrary answer.
Why do my standard-form coefficients differ from the textbook?
Multiplying A, B and C by the same non-zero number gives the same line. The result is tidied so that A is not negative and whole-number coefficients are divided by their greatest common divisor, so compare after simplifying yours the same way.
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/geom/line-equation \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x1":0,"y1":0,"x2":2,"y2":4}'const res = await fetch("https://api.kit.forhosting.com/geom/line-equation", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x1": 0,
"y1": 0,
"x2": 2,
"y2": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/geom/line-equation",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x1": 0,
"y1": 0,
"x2": 2,
"y2": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/geom/line-equation", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x1":0,"y1":0,"x2":2,"y2":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x1":0,"y1":0,"x2":2,"y2":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/geom/line-equation", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"x1": 0,
"y1": 0,
"x2": 2,
"y2": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "geom.line_equation",
"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
Missing fields, empty strings, non-numeric text, NaN, Infinity, and identical endpoints are rejected with a clear invalid_input error instead of a silent NaN slope or an arbitrary line. No network calls, no random sampling, and no floating-point surprises beyond ordinary IEEE-754 arithmetic on the four numbers you provide.
How two points determine slope-intercept and standard forms
Large coordinates can still overflow IEEE-754 range; non-finite intermediate results fail with a clear overflow message rather than returning Infinity in JSON.
What you send and what you get back
Provide four required finite numbers: x1 and y1 for the first point, x2 and y2 for the second. Wire the free browser tool for quick sanity checks, then call the identical contract from scripts when you need bulk evaluation without reimplementing the numeric gate in every language. Short aliases ax, ay, bx, by and x_a through y_b are accepted so form labels can stay compact without diverging handlers. Missing fields, empty strings, non-numeric text, NaN, and Infinity are rejected with invalid_input and are not charged. If both coordinates match so the points coincide, the request also fails with invalid_input naming that a unique line requires two distinct points. On success the JSON response echoes the four normalized coordinates, returns slope and intercept as numbers or null for vertical lines, provides slope_intercept as a compact string such as y equals 2x plus 1 or null when vertical, returns standard as an object with A, B, and C, returns standard_form as a readable equation string, and sets is_vertical and is_horizontal booleans. Example checks: zero, zero, two, four yields slope two, intercept zero, slope-intercept y equals 2x, and a reduced standard form; one, one, one, five is vertical with null slope and standard form x minus one equals zero; identical endpoints fail. API pricing is the published base of $0.002 per successful item.
Where line equations from two points show up in real work
Drafting and simple GIS workflows that already project endpoints into a local Cartesian plane need the same algebraic description before reporting a boundary segment so field notes and office scripts stay aligned. Because this capability is a pure parse engine, failed validation does not consume balance and successful runs stay at $0.002 per item.
Integration use cases
CAD and drafting helpers
From two snap endpoints, recover a closed line equation for overlays, constraints, and report fields.
Deterministic geometry fixtures
Generate stable equation strings and coefficient triples for unit tests and teaching answer keys.
Technical questions
What forms does this calculator return?
Slope-intercept y = mx + b when the line is non-vertical, and always standard form Ax + By + C = 0 with numeric A, B, C and a readable equation string.
What happens if the two points are the same?
The request fails with invalid_input. A unique line requires two distinct points; coincident endpoints are not accepted.
How are vertical lines handled?
Slope, intercept, and slope_intercept are null, is_vertical is true, and standard form still describes the line (for example x − 3 = 0).