UKismetMathLibrary::MinAreaRectangle
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallable
Description
Finds the smallest-area rectangle that encloses a set of coplanar points, using an exhaustive rotating-calipers-style search. Commonly used to fit a bounding rectangle around a navigable area, a room footprint, or a cluster of markers.
Caveats & Gotchas
- • InPoints must actually be coplanar (or very nearly so) — points scattered across a volume rather than a flat plane produce a meaningless or degenerate rectangle since the algorithm projects onto the plane defined by SampleSurfaceNormal.
- • This is an exhaustive O(n^2) or worse search over point pairs (per the referenced geometrictools.com algorithm), so calling it every frame on a large or growing point set can be a real performance cost — cache the result when the input points are static.
Signature
static void MinAreaRectangle(UObject* WorldContextObject, const TArray<FVector>& InPoints, const FVector& SampleSurfaceNormal, FVector& OutRectCenter, FRotator& OutRectRotation, float& OutRectLengthX, float& OutRectLengthY, bool bDebugDraw = false) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | UObject* | World context pointer; only used when bDebugDraw is enabled. | — |
| InPoints | const TArray<FVector>& | The points to enclose in the rectangle. Must lie within the same plane for correct results. | — |
| SampleSurfaceNormal | const FVector& | Normal indicating the surface direction the points lie on. | — |
| OutRectCenter | FVector& | Output: translation of the rectangle from the origin. | — |
| OutRectRotation | FRotator& | Output: rotation of the rectangle relative to the XY plane. | — |
| OutRectLengthX | float& | Output: length of the rectangle along its X axis, before rotation. | — |
| OutRectLengthY | float& | Output: length of the rectangle along its Y axis, before rotation. | — |
| bDebugDraw | bool | If true, draws the resulting rectangle for debugging, provided WorldContextObject is valid. | false |
Return Type
void Example
Fit a rectangle around a room's floor points C++
FVector Center, RectRot;
FRotator OutRotation;
float LengthX, LengthY;
UKismetMathLibrary::MinAreaRectangle(this, FloorPoints, FVector::UpVector, Center, OutRotation, LengthX, LengthY, /*bDebugDraw=*/true); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?