Vec2ToScalarBinaryOperation
Get a single number out of two 2D vectors
- a
- b
- FLOAT
Some questions about two 2D vectors don't have a vector answer - they have a number answer. How far apart are these two points? How aligned are these two directions? Vec2ToScalarBinaryOperation takes two VEC2 values and collapses them down to a single FLOAT, using one of two standard vector operations.
It's part of ComfyMath, evanspearman's math/logic pack - the sibling of CM_Vec2BinaryOperation (which returns a vector) for the cases where what you actually want back is one plain number.
How it works
Feed it a and b, both VEC2 (default [0, 0]), and pick an op: Dot or Distance. Dot is the dot product - a standard way to measure how aligned two directions are (a positive result means they point roughly the same way, a negative result means roughly opposite, zero means perpendicular). Distance is exactly what it sounds like: the straight-line distance between the two points the vectors represent.
Distance is the one you'll reach for more often in a typical graph - checking how far a computed position drifted from a target, measuring the size of a movement, that kind of thing. Dot is more useful if you're doing anything involving direction or alignment, like checking whether a motion vector is heading roughly the same way as a reference direction.
Inputs and outputs
op- Dot or Distance.a(VEC2, default[0, 0]) andb(VEC2, default[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. They're easy to conflate if you're not used to vector math - Dot measures alignment/direction (and its magnitude depends on both vectors' lengths, not just their positions), Distance measures literal separation between two points. If the number coming out doesn't match your intuition, double check which one is selected.
The FLOAT output feeds into something expecting a comparison already done. This node only produces the number - if you need a yes/no answer (e.g. "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 Vec2 nodes at all. Most generation workflows never touch them - they're for when you're building your own coordinate, offset, or motion 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 | VEC2 | 0,0 | — |
| b | VEC2 | 0,0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| FLOAT | FLOAT | — |