Compute the angle between two line segments (0–180°), direction angles (0–360°), lengths, and parallel/perpendicular status. Visualize segments on a dynamic canvas.
The angle between two line segments is derived from their direction vectors. Given segment AB = (B−A) and segment CD = (D−C), the cosine of the angle θ is defined by the dot product formula:
where θ ∈ [0°, 180°]. The direction angle (bearing) of a single segment relative to the positive x‑axis is computed via atan2(dy, dx) and converted to degrees in [0°,360°). This calculator also checks for perpendicularity (|θ − 90°| < tolerance) and parallelism (θ < 1° or θ > 179°).
We use double-precision arithmetic to avoid catastrophic cancellation. For degenerate cases where segment length approaches zero, the tool displays an error. The dot product method yields the smaller angle between vectors; for oriented angles (signed) one would consider cross product, but we focus on the unsigned geometric angle — the most common requirement in design and navigation.
Our implementation follows the standard from analytic geometry textbooks (Larson, Stewart). The direction angle is normalized to [0, 360) by adding 360° when atan2 returns negative.
1️⃣ Extract vectors: u = (Bx−Ax, By−Ay), v = (Dx−Cx, Dy−Cy).
2️⃣ Compute lengths L₁ = sqrt(ux²+uy²), L₂ = sqrt(vx²+vy²).
3️⃣ Dot = ux*vx + uy*vy.
4️⃣ Angle θ = arccos( dot / (L₁·L₂) ) in radians → degrees.
5️⃣ Direction φ₁ = atan2(uy, ux) → degrees, normalized to 0–360.
| Example Pair | Coordinates (A,B) & (C,D) | Angle between | Direction 1/2 | Relation |
|---|---|---|---|---|
| Perpendicular | (0,0)-(4,0) and (2,0)-(2,3) | 90.0° | 0° / 90° | Perpendicular |
| Parallel (45°) | (0,0)-(2,2) and (1,1)-(3,3) | 0.0° | 45° / 45° | Parallel |
| Acute 60° | (0,0)-(4,0) and (0,0)-(2,3.464) | 60.0° | 0° / 60° | Acute angle |
| Obtuse 120° | (0,0)-(4,0) and (0,0)-(-2,3.464) | 120.0° | 0° / 120° | Obtuse angle |
A two‑link robotic arm needs to position its end effector. Segment AB represents the upper arm, segment CD represents the forearm. The angle between them determines the wrist orientation. Using our calculator, an engineer can compute the instantaneous joint angle (e.g., 142.3°) and adjust motor commands. The interactive graph helps visualize workspace limits. This direct feedback loop accelerates prototyping.