Nodes/ComfyMath/Vec2BinaryOperation
ComfyUI Node

Vec2BinaryOperation

Add, subtract, or cross two 2D vectors

By evanspearman·Created 3 years ago·Updated about a year ago· 192
Vec2BinaryOperation
  • a
  • b
  • VEC2
op

Whenever a graph is treating a width/height pair or an X/Y offset as one value instead of two separate floats, combining two of them is where this node comes in. Vec2BinaryOperation takes two VEC2 vectors and combines them - add one offset to another, find the difference between two positions - and hands back a VEC2.

It's part of ComfyMath, evanspearman's math/logic node pack, and it's the vector equivalent of the plain arithmetic nodes elsewhere in the pack, just operating on paired values instead of single numbers.

How it works

Feed it a and b, both VEC2 (default [0, 0]), and pick an op: Add, Sub, or Cross. Add and Sub do exactly what you'd guess - component-wise addition or subtraction, useful for combining offsets or finding the vector between two points. Cross is worth a note: a "cross product" between two 2D vectors is conventionally a single scalar number (sometimes called the perp-dot product), not another vector - but this node's output socket is VEC2 either way. If you specifically need Cross, it's worth a quick sanity check on what actually comes out before you build downstream logic on top of it, rather than assuming standard 2D cross-product math.

Inputs and outputs

  • op - Add, Sub, or Cross.
  • a (VEC2, default [0, 0]) and b (VEC2, default [0, 0]) - the two vectors being combined.
  • Output: VEC2 - the result, ready to feed into another Vec2 node or wherever your graph expects a paired value.

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 - a plain Python math pack.

Common issues & troubleshooting

Cross doesn't behave like you expected. As above, standard 2D cross product returns a scalar, so if you need that specific scalar quantity, test what this node actually outputs first - ComfyMath's CM_Vec2ToScalarBinaryOperation (with Dot or Distance) might be closer to what you actually want if it's a single number you're after.

A VEC2 output won't connect where you expect. VEC2 is a distinct type from a pair of loose FLOATs - if a target node wants two separate FLOAT sockets instead of one VEC2, you'll need a node that splits a vector back into components rather than wiring VEC2 straight in.

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

You're not sure you even need Vec2 nodes. Fair - most ComfyUI workflows never touch them. They show up when you're doing your own offset/tiling/coordinate math (compositing positions, tile-layout calculations, camera or motion-vector work) rather than in a typical generation graph.

The pack looks unmaintained. A 2024 community thread noted the author had stepped back from active development. The Vec2/Vec3 side of ComfyMath is its least-touched corner, which cuts both ways: little chance of new features, but also little that's likely to break.

Categorymath/vec2

Inputs (3)

NameTypeDefaultDescription
opCOMBO3 options: Add, Sub, Cross
aVEC20,0
bVEC20,0

Outputs (1)

NameTypeDescription
VEC2VEC2