atan2
The quadrant-aware angle from x and y
- y
- x
- FLOAT
The correct version of the arctangent
Here's the difference that matters: atan(y/x) can't tell 45° from 225°, because dividing destroys the sign information. atan2(y, x) takes the two coordinates separately and returns the angle that actually points where your vector points - 0° to 180° or 0° to -180°, full circle, quadrant correct. If you're computing an angle from a position, a direction, or an offset, this is the node you want, not atan.
The canonical example: a vector pointing up-left has y/x equal to one pointing down-right, but the two directions are 180° apart. atan2 knows the difference. It also handles the case that breaks plain division: x = 0. Dividing by zero is a crash; atan2 just returns ±90°.
How it works
The node computes math.atan2(y, x) and converts to degrees if you've selected that unit (the default). Note the argument order matters and is easy to get backwards: it's atan2(y, x), vertical first. Swap them and every angle comes out rotated 90°. The result is in the range -180° to 180° (or -π to π in radians), so negative angles mean "measured clockwise from the positive x-axis" - that trips up people used to 0–360° compass math. If you want a 0–360° heading, add 360 to any negative result.
Both inputs are text fields that take plain numbers (float()-parsed). The pack's inverse-trig convention holds: no expressions here, just values, and the pack's formula node exists for actual math.
Inputs and outputs
- y (FLOAT or INT, default
0) - vertical component. - x (FLOAT or INT, default
0) - horizontal component. - unit (enum, default
degrees) -radiansordegrees.
Output is a single FLOAT: the angle of the vector (y, x), quadrant-correct.
Installing it
Part of Basic data handling by StableLlama, the r/StableDiffusion regular known for his deep-dive model comparisons (Flux Klein 9B, RealVisXL) more than his code. The pack is intentionally plain - zero runtime dependencies in its pyproject, no model files, no GPU work.
Install via ComfyUI Manager (search "Basic data handling") or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI; it's under Basic/maths.
Troubleshooting
The two ways to get a wrong answer: swapping y and x (order is y first, and it's a surprisingly easy mistake), and expecting a 0–360° output when the node returns -180 to 180. Neither is a crash - you just get a silently wrong angle, so double-check both if results look off. Remember atan2 is for coordinate pairs; a single slope value belongs in the plain atan node.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| y | FLOAT,INT | 0 | — |
| x | FLOAT,INT | 0 | — |
| unit | COMBO | degrees | 2 options: radians, degrees |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |