Vec4ToScalarUnaryOperation
Get the length of a 4D vector
- a
- FLOAT
If you're carrying a color, a quaternion, or a homogeneous coordinate as a VEC4 and you need to know its magnitude - not what it represents, just how "big" it is as a plain number - this is the node for that one question. Vec4ToScalarUnaryOperation takes one VEC4 and returns its length as a FLOAT.
It's part of ComfyMath, evanspearman's math/logic pack, and it pairs naturally with CM_Vec4UnaryOperation's Normalize (which uses the exact same length calculation internally to scale a vector down to unit length) and CM_Vec4UnaryCondition'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 (VEC4, default [0, 0, 0, 0]), and it returns sqrt(x² + y² + z² + w²) - the 4D extension of Pythagoras across all four components.
If you're treating a VEC4 as a quaternion, this is a genuinely useful check: a valid rotation quaternion should have a norm of 1, so running one through here tells you whether it's still a clean unit quaternion or has drifted after a chain of operations. Outside of that, it's the same tool as the VEC2/VEC3 versions - checking how far a computed value has moved from the origin, regardless of direction.
Inputs and outputs
op- Norm (the only choice).a(VEC4, default[0, 0, 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_Vec4ToScalarBinaryOperation 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, 0, 0] - check whatever's feeding this node's a input; the default is [0, 0, 0, 0], so an unconnected or accidentally-default input will always norm to zero.
A quaternion's norm isn't exactly 1 anymore. Rounding drift from a chain of operations upstream is the usual culprit, not a broken node - this is exactly the kind of thing this node is useful for catching before it causes a visibly wrong rotation downstream.
Missing node error loading a shared workflow. Install ComfyMath via Manager as above, then reload.
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 | VEC4 | 0,0,0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |