Vec4ToScalarBinaryOperation
Get a single number out of two 4D vectors
- a
- b
- FLOAT
Some questions about two 4D vectors don't have a vector answer - they have a number answer. How far apart are these two colors or coordinates? How aligned are these two quaternions? Vec4ToScalarBinaryOperation takes two VEC4 values and collapses them to a single FLOAT.
It's part of ComfyMath, evanspearman's math/logic pack - the sibling of CM_Vec4BinaryOperation (which returns a vector) for cases where what you actually want back is one plain number.
How it works
Feed it a and b, both VEC4 (default [0, 0, 0, 0]), and pick an op: Dot or Distance. Dot is the standard four-component dot product - multiply matching components and sum them. It's a genuinely well-defined operation at any dimension, unlike cross product, so this one behaves exactly the way you'd expect coming from the VEC2 or VEC3 versions of this node: positive means roughly aligned, negative means roughly opposed, zero means orthogonal. Distance is the straight-line distance between the two points the vectors represent, treating all four components as coordinates in 4D space.
Distance is the more intuitive one if you're comparing colors or positions - how far apart are these two RGBA values, numerically. Dot matters more for direction and alignment questions, which comes up if you're doing anything quaternion-adjacent, since the dot product of two quaternions is a standard way to measure how close two rotations are to each other.
Inputs and outputs
op- Dot or Distance.a(VEC4, default[0, 0, 0, 0]) andb(VEC4, default[0, 0, 0, 0]) - the two vectors.- Output:
FLOAT- the resulting scalar.
How to install it
Via 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 math.
Common issues & troubleshooting
You picked Dot but wanted a plain distance, or vice versa. Dot measures alignment/direction (and its magnitude depends on both vectors' lengths, not just their positions), Distance measures literal separation. If the number doesn't match your intuition, double check which one is selected.
The FLOAT output feeds into something expecting a yes/no answer already. This node only produces the number - if you need "is this distance under some threshold," pair the output with CM_FloatUnaryCondition or a similar comparison node downstream rather than expecting this one to do both steps.
Missing node error loading a shared workflow. Install ComfyMath via Manager as above, then reload.
Not sure you need Vec4 nodes at all. Most generation workflows never touch them - they're for when you're building your own color, quaternion, or homogeneous-coordinate math rather than a standard checkpoint-to-image pipeline.
The pack looks quiet. A 2024 community thread noted the author had stepped back from active development. Pure vector math has little to break, so it's a stable, finished corner of the pack rather than a concerning one.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| op | COMBO | 2 options: Dot, Distance | |
| a | VEC4 | 0,0,0,0 | — |
| b | VEC4 | 0,0,0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |