Do two segments intersect?
Check whether two finite segments really meet: the segments from (0, 0) to (4, 4) and from (0, 4) to (4, 0) cross at (2, 2), halfway along each. Touches at an end and overlaps are reported too. 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
- 4
- Y2
- 4
- X3
- 0
- Y3
- 4
- Kind
- proper
- X
- 2
- Y
- 2
- T
- 0.5
You supply eight finite numbers—x1, y1, x2, y2 for segment AB and x3, y3, x4, y4 for segment CD—and the engine solves the parametric equations A plus t times (B minus A) equals C plus u times (D minus C) with both parameters constrained to the closed unit interval. When the segments miss each other it returns intersects false with kind none and omits the point fields.
Why a segment is not a whole line
A line segment is the closed stretch of points between two end points, not the infinite line that runs through them. That difference decides the answer. Two lines that are not parallel always cross somewhere, but the crossing can sit far beyond the ends of the segments you care about, such as two walls on a plan, two road links on a map or two edges of a polygon. The checker writes each segment as a start point plus a fraction of its length, and accepts a crossing only when both fractions stay between 0 and 1, so the shared point really lies on both pieces.
Crossing, touching and overlapping
Two segments can meet in three ways. They can cross properly, each passing through the inside of the other, as the diagonals from (0, 0) to (4, 4) and from (0, 4) to (4, 0) do at (2, 2). They can touch only at an end point, the T-junction or shared corner that matters when you check whether a layout is connected. Or they can lie on the same line and overlap along a piece. The answer names the kind of contact, gives a shared point and the two fractions, and plainly says no when the segments miss each other.
Where segment intersection checks fit in study, design, and code
Students meet segment intersection when they study coordinate geometry, polygon edges, and the distinction between open and closed intervals on a line. Architects, surveyors, and game-level designers often need whether two walls, roads, or path edges actually meet inside their finite lengths before they treat a layout as connected. Developers call the same contract from scripts to seed deterministic test vectors for geometry libraries, to illustrate computational-geometry orientation tests in teaching tools, or to satisfy programming-challenge statements that demand exact segment–segment answers.
Pair it with the midpoint and section-formula tools when you already know a segment and need interior points, with the infinite-line intersection calculator when you intentionally want the supporting-line crossing even outside the segments, and with polygon-area helpers when edge intersections feed into larger planar figures.
What you can do with it
Mesh, CAD, and map edge checks
Tools that validate polygon edges, road links, or wall layouts can ask whether two finite segments share a point before treating a graph as connected.
FAQ
What does the segment intersection checker cost?
It is free in your browser on this page.
Which inputs are required?
Eight finite coordinates: x1,y1,x2,y2 for segment AB and x3,y3,x4,y4 for segment CD. Optional precision sets decimal places from 0 to 15 (default 10).
How is the intersection calculated?
Parametric form P = A + t(B−A) = C + u(D−C). Solve for t and u using the 2D cross product of the direction vectors; both parameters must lie in [0,1] for a closed-segment hit.
Why can two lines cross while their segments do not?
Lines go on forever, so two lines that are not parallel always meet somewhere. Segments stop at their end points, and the crossing of their lines may fall outside them, which this checker reports as no contact.
What kinds of contact can it report?
Three: a proper crossing through the inside of both segments, a touch at an end point such as a shared corner, and a collinear overlap where both lie on the same line and share a piece.
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/segment-intersection \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"x1":0,"y1":0,"x2":4,"y2":4,"x3":0,"y3":4,"x4":4,"y4":0}'const res = await fetch("https://api.kit.forhosting.com/geom/segment-intersection", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"x1": 0,
"y1": 0,
"x2": 4,
"y2": 4,
"x3": 0,
"y3": 4,
"x4": 4,
"y4": 0
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/geom/segment-intersection",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"x1": 0,
"y1": 0,
"x2": 4,
"y2": 4,
"x3": 0,
"y3": 4,
"x4": 4,
"y4": 0
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/geom/segment-intersection", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"x1":0,"y1":0,"x2":4,"y2":4,"x3":0,"y3":4,"x4":4,"y4":0}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"x1":0,"y1":0,"x2":4,"y2":4,"x3":0,"y3":4,"x4":4,"y4":0}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/geom/segment-intersection", 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": 4,
"y2": 4,
"x3": 0,
"y3": 4,
"x4": 4,
"y4": 0
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "geom.segment_intersection",
"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
This segment intersection checker answers a classic plane-geometry question: given two closed line segments by their four endpoints, do they cross or touch, and if so where? When a solution exists it returns intersects true, the kind of contact (proper crossing, endpoint touch, or collinear overlap), the coordinates of a shared point, and the parameters t and u. Missing or non-numeric endpoints fail immediately with invalid_input so failed validation is never charged.
What segment intersection means and how it differs from infinite lines
Search intent clusters around phrases such as do two segments intersect, segment intersection calculator, line segment cross check, and find intersection of two segments from coordinates. That intent is deliberately different from an infinite-line solver: extending both segments as full lines can invent a crossing far outside the finite edges that matter for polygons, collision bounds, and map links. In Euclidean plane geometry a line segment is the closed set of points between two endpoints, not the infinite line that extends through them. Two segments intersect when they share at least one common point: they may cross in their relative interiors (a proper intersection), meet only at an endpoint (a T-junction or shared vertex), or lie on the same supporting line and overlap on a subsegment or a single point (collinear contact). Students want a numeric yes-or-no with coordinates against a homework key; developers want a deterministic oracle for edge–edge tests in meshes, UI hit regions, and contest validators; survey and CAD assistants want structured JSON they can paste into reports without reimplementing orientation or Cramer arithmetic in every language. Delivering intersects, kind, and optional point fields as JSON makes the result easy to assert in continuous integration, feed into a larger pipeline, or copy into notes. The calculator treats segments as closed, so endpoint-to-endpoint contact counts as an intersection rather than a silent miss, which matches the usual closed-segment convention in computational geometry textbooks and school problems.
How endpoints are validated and how the intersection is computed
Computation uses the standard parametric form: write P equals A plus t times (B minus A) and also P equals C plus u times (D minus C), form the two-by-two system whose determinant is the two-dimensional cross product of the direction vectors, and solve for t and u. There is no third segment, no least-squares fit, and no unit conversion of the coordinates themselves; the arithmetic assumes a shared Cartesian frame. Send a JSON body with the eight required fields x1, y1, x2, y2, x3, y3, x4, and y4. Each field must be a finite number; JSON numbers and plain decimal strings are accepted, and short aliases such as ax, ay, bx, by, cx, cy, dx, and dy map onto the same coordinates. The engine rejects missing fields, empty strings, NaN, and infinities with invalid_input so those failed calls are not charged and never invent a fake crossing. When the determinant is safely nonzero and both parameters land in the closed unit interval, the segments meet at that P; endpoint contact is flagged when a parameter sits at zero or one. When the determinant vanishes the supporting lines are parallel: if the endpoints are not collinear there is no intersection; if they are collinear the engine checks whether any endpoint of one segment lies on the other and, when they overlap, reports intersects true with one representative shared point rather than an interval of solutions.
Where segment intersection checks fit in study, design, and code
A textbook may give four endpoints and ask whether the segments cross, or present a figure where only an infinite-line extension would meet; this checker returns a clear boolean plus coordinates when contact exists and kind none when it does not. Teachers can pre-generate answer keys that list intersects and the point for mixed proper, endpoint, and parallel cases, and rely on invalid_input for incomplete rows instead of printing a blank or a silent Infinity. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result.
Integration use cases
Homework and exam segment drills
Students and graders confirm whether two segments meet from eight endpoint coordinates, including proper crossings, endpoint touches, and clear misses, without a local computer-algebra system.
Deterministic geometry fixtures
Pipelines that seed unit tests, contest validators, and CI assertions can call a pure segment-intersection oracle instead of reimplementing parametric cross products in every language.
Technical questions
Do endpoint touches count as intersections?
Yes. Closed segments that share only a vertex or meet in a T-junction report intersects true with kind endpoint.
What if a coordinate is missing or not a number?
The handler returns invalid_input naming the failing field. Non-numeric or infinite endpoints never produce a fabricated intersection point.