ComfyUI Node

cos

Cosine of an angle — and the 90° gotcha

By StableLlama·Created about a year ago·Updated 4 days ago· 48
cos
  • angle
  • FLOAT
unitdegrees

The cosine of an angle, in degrees or radians

Cosine turns an angle into a ratio: the horizontal component of a direction, or the adjacent-over-hypotenuse ratio of a right triangle. cos(0°) is 1, cos(180°) is -1, and every angle in between maps to a value between those. In a ComfyUI workflow this is the node you'd reach for when you're doing any geometry - projecting a direction onto an axis, computing an offset, or converting an angle into a component.

It's the forward trig node of the pack's math family, and it's the one with the most beginner-bait built in, because of how units and floating point interact.

How it works

The node computes cos(angle), and the key detail is that the unit dropdown is applied on the way in: if you select degrees (the default), the angle is converted to radians before cosine is taken - math.cos() natively works in radians. That's exactly what you want: type 90, pick degrees, get ~0.

Which brings us to the gotcha. cos(90°) should be 0, and it is - approximately. You'll actually get 6.12e-17 (a tiny number, not exactly zero), because converting 90° to radians can't be done exactly in floating point. That's not a bug in this node; it's just how computers do trig. If your downstream logic checks if result == 0, it will never be true - compare with a small epsilon instead, or round the result.

Inputs and outputs

  • angle (FLOAT or INT, default 0) - the angle; note this one is called angle, not value, unlike the pack's other trig nodes.
  • unit (enum, default degrees) - radians or degrees.

Output is a single FLOAT: the cosine, always between -1 and 1.

The angle field is a text input that takes a plain number (float()-parsed). Wire another node's output into it if the angle is computed - the pack's formula node is where actual expressions belong.

Installing it

Part of Basic data handling by StableLlama, the r/StableDiffusion regular better known for his long model comparisons (Flux Klein 9B, RealVisXL) than for code. The pack is deliberately plain - zero runtime dependencies in its pyproject, no model files, no GPU involvement.

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

Three things to keep in mind. First, the 6e-17 non-zero result at 90° - don't compare against exact zero, compare against a tolerance. Second, the unit dropdown: feed radians while it's set to degrees and every angle is wrong by ~57.3×. Third, remember this is the forward direction - if you have a ratio and want the angle, that's the acos node next door.

CategoryBasic/maths

Inputs (2)

NameTypeDefaultDescription
angleFLOAT,INT0
unitCOMBOdegrees2 options: radians, degrees

Outputs (1)

NameTypeDescription
FLOATFLOAT