2D Geometry computation methods

Hi Guys,

I need to do some computations of 2D polygons in UE5 C++, such as if two polygons overlap, how do I get their vertex coordinates or other information of their intersection, union and difference sets?

For example the following the vertex, edge or other properties of the yellow polygon:

I have searched on Google and even ChatGPT for many days but I could not find a way to do it in UE5.
For now I prefer to import CGAL(Computational Geometry Algorithms Library) to UE5 and I found it is so complex to do that! I have downloaded CGAL via vcpkg but I am unable to import it to my UE5 project.

What should I do so I can get the result of intersection, union and difference sets?

Thanks so much!

Hi there,
did u find solution for cgal? i want to do it as well

If you’re using UE 5.3, there’s a plugin called Geometry Scripting that has this.

In C++, it’s in the Curve/PolygonIntersectionUtils.h header.

It has these functions:
bool PolygonsUnion(TArrayView< const FGeneralPolygon2d > Polygons, TArray< FGeneralPolygon2d >& ResultOut, bool bCopyInputOnFailure);

bool PolygonsDifference(TArrayView< const FGeneralPolygon2d > PosPolygons, TArrayView< const FGeneralPolygon2d > NegPolygons, TArray< FGeneralPolygon2d >& ResultOut);

bool PolygonsIntersection(TArrayView< const FGeneralPolygon2d > SubjPolygons, TArrayView< const FGeneralPolygon2d > ClipPolygons, TArray< FGeneralPolygon2d >& ResultOut);

bool PolygonsExclusiveOr(TArrayView< const FGeneralPolygon2d > SubjPolygons, TArrayView< const FGeneralPolygon2d > ClipPolygons, TArray< FGeneralPolygon2d >& ResultOut);

You can pass a TPolygon2 to FGeneralPolygon2d.

These functions are also available in Blueprint.

1 Like

It seems that UE update their 2D shapes calculations.
Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.