Vec2UnaryOperation
Negate or normalize a 2D vector
- a
- VEC2
Two of the most common single-vector transforms, in one node: flip it, or scale it down to a pure direction. Vec2UnaryOperation takes one VEC2 and applies either, returning a new VEC2.
It's part of ComfyMath, evanspearman's math/logic pack, and it's the node that pairs directly with the pack's own CM_Vec2ToScalarUnaryOperation (Norm, for measuring a vector's length) and CM_Vec2UnaryCondition (IsNormalized, for checking whether one's already unit length) - the three together cover most of what you'd want to do with a single 2D vector.
How it works
Feed it a (VEC2, default [0, 0]) and pick an op: Neg or Normalize. Neg flips both components - reverses the direction, same magnitude. Normalize scales the vector down so its length becomes 1 while keeping its direction - the standard move when you have a direction-plus-magnitude vector but only care about the direction going forward.
Worth knowing: normalizing a zero vector ([0, 0]) is mathematically undefined - there's no direction to preserve when there's no vector to begin with. If your graph might feed this node a zero vector, it's worth guarding against it with CM_Vec2UnaryCondition's IsZero check first, rather than assuming Normalize will hand back something sensible.
Neg is the safer of the two - it's defined everywhere, including on the zero vector (negating [0, 0] just gives you [0, 0] back), so it's the one you can use without a guard clause in front of it.
Inputs and outputs
op- Neg or Normalize.a(VEC2, default[0, 0]) - the vector being transformed.- Output:
VEC2- the result.
How to install it
Through ComfyUI Manager: search ComfyMath, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/evanspearman/ComfyMath.git
then restart ComfyUI. No dependencies, no models - plain Python.
Common issues & troubleshooting
Normalize gives back something unexpected (NaN, zero, or an error). Check whether a could be [0, 0] at that point in the graph - normalizing a zero-length vector isn't a well-defined operation, and this is the most likely source of a weird result. Guard it upstream with an IsZero check if there's any chance of that happening.
You expected Normalize's output length to read as exactly 1 in a downstream check. Floating-point math rarely lands on exactly 1.0 - if you're feeding this into CM_Vec2UnaryCondition's IsNormalized and it's coming back false, that's rounding error, not a bug.
Missing node error loading a shared workflow. Install ComfyMath via Manager as above, then reload.
Not sure you need Vec2 nodes. Most workflows don't touch them - this is for graphs doing their own direction, offset, or coordinate math.
The pack looks unmaintained. A 2024 community thread noted the author had stepped back from active development. It's simple vector math with no external dependencies, so there's little for it to break on.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| op | COMBO | 2 options: Neg, Normalize | |
| a | VEC2 | 0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| VEC2 | VEC2 | — |