#### C++ Get UV coordinates in circular area

I’m trying to make a function for my Unreal Engine project, that will take in a UV coordinate as the centre point of a circle, the radius of the circle in pixel space and the resolution of the texture, and using this information generate an array of UV coordinates in the circle. As I’m trying to optimise for VR, is there a better way to do this than my current code? I need to perform this operation a few dozen times, but at the moment a single iteration still takes a while.

``````TArray<FVector2D> Uread_write_text::CircularUV(FVector2D centre, int radius, FVector2D resolution) {
TArray<FVector2D> uvs;

// Iterate through pixel space, by getting the centre in UV space and finding it's
// equilavent in pixel space and then find the extents.
for (int i = FGenericPlatformMath::TruncToInt((centre.X * resolution.X) - radius);
i < FGenericPlatformMath::TruncToInt((centre.X * resolution.X) + radius);
i++) {

for (int j = FGenericPlatformMath::TruncToInt((centre.Y * resolution.Y) - radius);
j < FGenericPlatformMath::TruncToInt((centre.Y * resolution.Y) + radius);
j++) {

// Checks if i and j is within the circle radius, therefore the coordinates are within the circle
if ((i <= (centre.X * resolution.X) + radius) & (i >= (centre.X * resolution.X) - radius)) {
if ((j <= (centre.Y * resolution.Y) + radius) & (j >= (centre.Y * resolution.Y) - radius)) {

// Does the final conversion back to UV space once it has been confirmed that it is
// a correct coordinate
float x = i / resolution.X;
float y = j / resolution.Y;

// Adds it to the return value
uvs.Add(FVector2D(x, y));

}
}
}

}

return uvs;
}
``````

Source: Windows Questions C++