ComfyUI Node

Pt Acos

Arccos, for when your angles need reversing

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Acos
  • tens_a
  • TENSOR

Pt Acos is the inverse of the cosine: feed it a cosine value and it hands back the angle in radians. It's a niche math wrapper in ComfyUI-Pt-Wrapper, and honestly you can go a long time in the pack without needing it - but when an angle is what you want, it's the exact right tool and there's no point hand-rolling it.

It's part of the trig family in HowToSD's 200-node PyTorch pack (the spin-off of ComfyUI-Data-Analysis), alongside Asin and Atan. Where do arccosines actually earn their keep in tensor work? The big one is cosine similarity → angle. If you compute cosine similarity between two embeddings (a common trick in feature-space work - how aligned are two vectors), the raw number lives in [−1, 1], and arccos converts that similarity into a genuine angular distance in [0, π]. That's the move people are actually after when they say "how far apart are these features": angle, not similarity. The inverse-cosine also shows up in geometry-ish tensor math - angular error metrics, rotation recovery, PCA-related decompositions.

How it works. One input, tens_a; one output, TENSOR. Element-wise acos(), radians output, same shape. Zero settings.

The trap is mathematical, and it's a real one. Arccos is only defined for inputs in [−1, 1]. Feed it a 1.05 - which happens constantly when cosine similarities drift out of range due to float error or a missing normalization step - and you get NaN. This is the classic "my angles are all NaN" workflow failure, and it's not a bug in the node, it's a domain error upstream: your cosine-similarity computation didn't normalize, or accumulated rounding error pushed a value past 1. Fix by clamping the input to [−1, 1] before the acos, or by normalizing the vectors you're measuring. Check for it by inspecting the input tensor's range - if anything is outside [−1, 1], that's your culprit.

Also worth knowing: output is in radians, not degrees. If you're thinking in degrees (angles around 0–360), you'll need to scale by 180/π downstream - another classic source of "my math is exactly wrong by a factor of 57."

Install: ComfyUI Manager → "ComfyUI-Pt-Wrapper", or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

then restart. No model downloads; the pack's heavy requirements.txt is the only install cost.

Troubleshooting: NaN everywhere - input out of [−1, 1]; clamp or normalize. Angles look "off" - you're reading radians as degrees or vice versa. Node works but output is useless - check you actually wanted arccos and not arctan; for "angle from a ratio" (opposite/adjacent) Atan is the right tool, not Acos.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tens_aTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR