Nodes/ComfyMath/Vec3ToScalarBinaryOperation
ComfyUI Node

Vec3ToScalarBinaryOperation

Get a single number out of two 3D vectors

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

Some questions about two 3D vectors don't have a vector answer - they have a number answer. How far apart are these two points in space? How aligned are these two directions? Vec3ToScalarBinaryOperation takes two VEC3 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_Vec3BinaryOperation (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 VEC3 (default [0, 0, 0]), and pick an op: Dot or Distance. Dot is the dot product - a standard way to measure how aligned two directions are (positive means roughly the same way, negative means roughly opposite, zero means perpendicular). It's also the calculation behind lighting math in 3D graphics - "how much does this surface face the light" is a dot product under the hood. 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 3D position drifted from a target, measuring the size of a movement. Dot matters more when direction and alignment are what you're actually asking about, rather than separation.

Inputs and outputs

  • op - Dot or Distance.
  • a (VEC3, default [0, 0, 0]) and b (VEC3, default [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. 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 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 Vec3 nodes at all. Most generation workflows never touch them - they're for when you're building your own 3D coordinate, camera, 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.

Categorymath/vec3

Inputs (3)

NameTypeDefaultDescription
opCOMBO2 options: Dot, Distance
aVEC30,0,0
bVEC30,0,0

Outputs (1)

NameTypeDescription
FLOATFLOAT