Nodes/ComfyMath/Vec4UnaryOperation
ComfyUI Node

Vec4UnaryOperation

Negate or normalize a 4D vector

By evanspearman·Created 3 years ago·Updated about a year ago· 192
Vec4UnaryOperation
  • a
  • VEC4
op

Two of the most common single-vector transforms, in one node: flip it, or scale it down to unit length. Vec4UnaryOperation takes one VEC4 and applies either, returning a new VEC4.

It's part of ComfyMath, evanspearman's math/logic pack, and it's the node that pairs directly with the pack's own CM_Vec4ToScalarUnaryOperation (Norm, for measuring a vector's length) and CM_Vec4UnaryCondition (IsNormalized, for checking whether one's already unit length) - the three together cover most of what you'd want to do with a single 4D vector.

How it works

Feed it a (VEC4, default [0, 0, 0, 0]) and pick an op: Neg or Normalize. Neg flips all four components. Normalize scales the vector down so its length becomes 1 while keeping its "direction" in 4D space - the operation you need if you're treating a VEC4 as a rotation quaternion, since a quaternion only represents a valid rotation when it's unit length. (One quirk if quaternions are what you're doing: q and -q represent the exact same rotation, so don't be surprised if a workflow works identically before and after a Neg - that's expected, not a sign the node did nothing.)

Worth knowing: normalizing a zero vector ([0, 0, 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, guard against it with CM_Vec4UnaryCondition's IsZero check first, rather than assuming Normalize will hand back something sensible.

Inputs and outputs

  • op - Neg or Normalize.
  • a (VEC4, default [0, 0, 0, 0]) - the vector being transformed.
  • Output: VEC4 - 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, 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_Vec4UnaryCondition's IsNormalized and it's coming back false, that's rounding error, not a bug.

Negating a quaternion "did nothing." If a represents a rotation, that's expected - q and -q are the same rotation, so Neg on a quaternion is a mathematically real change that has no visible effect downstream. It's not a broken node.

Missing node error loading a shared workflow. Install ComfyMath via Manager as above, then reload.

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.

Categorymath/vec4

Inputs (2)

NameTypeDefaultDescription
opCOMBO2 options: Neg, Normalize
aVEC40,0,0,0

Outputs (1)

NameTypeDescription
VEC4VEC4