Vec2ToScalarUnaryOperation
Get the length of a 2D vector
- a
- FLOAT
If you're carrying a direction or an offset as a VEC2 and you need to know how big it is - not which way it points, just its magnitude - this is the node for that one question. Vec2ToScalarUnaryOperation takes one VEC2 and returns its length as a plain FLOAT.
It's part of ComfyMath, evanspearman's math/logic pack, and it pairs naturally with CM_Vec2UnaryOperation's Normalize (which uses the exact same length calculation internally to scale a vector down to unit length) and CM_Vec2UnaryCondition's IsNormalized check (which is effectively asking "is this length already 1?").
How it works
There's only one operation available: Norm - the vector's norm, i.e. its length or magnitude. Feed it a (VEC2, default [0, 0]), and it returns the straight-line distance from the origin to the point (a.x, a.y) represents. If a is [3, 4], you'd expect 5 back - the classic 3-4-5 right triangle.
Practically, this is what you reach for to check how far a movement or offset vector actually travels regardless of direction: is a computed displacement bigger than some threshold, how much did a tracked position shift, that kind of thing. It's also the calculation Normalize needs internally - dividing a vector by its own norm is exactly how you scale something down to unit length - so if you're debugging why CM_Vec2UnaryOperation's Normalize output looks off, running the same vector through this node first tells you the length it's dividing by.
Inputs and outputs
op- Norm (the only choice).a(VEC2, default[0, 0]) - the vector being measured.- Output:
FLOAT- the vector's length.
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
You wanted the distance between two points, not the length of one vector. This node measures a single vector's magnitude, which is the distance from the origin - if you actually want the distance between two arbitrary points, use CM_Vec2ToScalarBinaryOperation with the Distance operation instead, feeding it both points.
The result is 0 and you didn't expect that. That means a is (or evaluates to) [0, 0] - check whatever's feeding this node's a input; the default is [0, 0], so an unconnected or accidentally-default input will always norm to zero.
Missing node error loading a shared workflow. Install ComfyMath via Manager as above, then reload.
Not sure you need this node. Most ComfyUI workflows never touch Vec2 math - this shows up specifically in graphs doing your own offset, motion, or coordinate calculations rather than a typical generation pipeline.
The pack is quiet on updates. A 2024 community thread noted the author had stepped back from active development. It's simple, dependency-free math, so there's little here for a ComfyUI update to break.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| op | COMBO | 1 options: Norm | |
| a | VEC2 | 0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |