UKismetMathLibrary::Hypotenuse
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the length of the hypotenuse of a right-angled triangle given its two legs (sqrt(Width^2 + Height^2)). Useful for computing 2D distances without constructing a vector.
Caveats & Gotchas
- • This computes a 2D distance only — for 3D Euclidean distance use FVector::Dist or UKismetMathLibrary::VSize instead.
- • Internally uses FMath::Sqrt(Width*Width + Height*Height); for very large inputs the intermediate squaring can overflow to infinity before the sqrt, producing incorrect results. FMath::Hypot (if available) uses a numerically stable algorithm — prefer that in precision-critical code.
Signature
static ENGINE_API double Hypotenuse(double Width, double Height); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Width | double | The horizontal leg of the right triangle. | — |
| Height | double | The vertical leg of the right triangle. | — |
Return Type
double Example
Compute 2D screen distance between two UI elements C++
FVector2D PosA(100.0f, 200.0f);
FVector2D PosB(400.0f, 600.0f);
double Dist = UKismetMathLibrary::Hypotenuse(PosB.X - PosA.X, PosB.Y - PosA.Y);
// Dist == 500.0 See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?