Hi, i’m trying to create some zone around point.
I did found the tutorial from : https://www.geeksforgeeks.org/convex-hull-set-1-jarviss-algorithm-or-wrapping/?fbclid=IwAR1ZKIpsH9MB9SHdY2hh8UUWMwD85jDvpNo_VFsGZYYk1J118RLwmBOdVGk
I tryied it to make it for c++ but seem to be stuck.
here’s the code (if someone can correct it for me) :
.h
UFUNCTION(BlueprintCallable, Category = "Physics")
static TArray<FVector> JarvisAlgorithm(TArray<FVector> Points, int MaxPoints);
static int orientation(FVector P, FVector Q, FVector R);
.cpp
TArray<FVector> UMyBlueprintFunctionLibrary::JarvisAlgorithm(TArray<FVector> Points, int MaxPoints)
{
int L = 0;
TArray<FVector> Hull;
for (int j = 1; j < MaxPoints; j++)
{
if (Points[j].X < Points[L].X) {
L = j;
}
};
int P = L;
int Q;
do {
Hull.Add(Points[P]);
Q = (P + 1) % MaxPoints;
for (int i = 0; i < MaxPoints; i++)
{
if (orientation(Points[P], Points*, Points[Q]) == 2)
{
Q = i;
}
}
} while (P != L);
return Hull;
};
int UMyBlueprintFunctionLibrary::orientation(FVector P, FVector Q, FVector R)
{
int val = (Q.Y - P.Y) * (R.X - Q.X) -
(Q.X - P.X) * (R.Y - Q.Y);
if (val == 0) return 0; // colinear
return (val > 0) ? 1 : 2; // clock or counterclock wise
};
I hope to find the solution