Nodes/ComfyMath/Vec3ToScalarUnaryOperation
ComfyUI Node

Vec3ToScalarUnaryOperation

Get the length of a 3D vector

By evanspearman·Created 3 years ago·Updated about a year ago· 192
Vec3ToScalarUnaryOperation
  • a
  • FLOAT
op

If you're carrying a direction or an offset as a VEC3 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. Vec3ToScalarUnaryOperation takes one VEC3 and returns its length as a plain FLOAT.

It's part of ComfyMath, evanspearman's math/logic pack, and it pairs naturally with CM_Vec3UnaryOperation's Normalize (which uses the exact same length calculation internally to scale a vector down to unit length) and CM_Vec3UnaryCondition'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 (VEC3, default [0, 0, 0]), and it returns the straight-line distance from the origin to the point (a.x, a.y, a.z) represents - the 3D version of Pythagoras: sqrt(x² + y² + z²).

Practically, this is what you reach for to check how far a computed 3D movement or offset actually travels regardless of direction: is a displacement bigger than some threshold, how much did a tracked position shift. 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 CM_Vec3UnaryOperation'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 (VEC3, default [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_Vec3ToScalarBinaryOperation 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] - check whatever's feeding this node's a input; the default is [0, 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 Vec3 math - this shows up specifically in graphs doing your own offset, motion, or 3D 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.

Categorymath/vec3

Inputs (2)

NameTypeDefaultDescription
opCOMBO1 options: Norm
aVEC30,0,0

Outputs (1)

NameTypeDescription
FLOATFLOAT