FMath::PointsAreCoplanar bug if three first points are aligned

FMath::PointsAreCoplanar always returns false when the three first points are aligned (since the normal - computed with the three first points - will be null).

This would not be a real problem if it were highlighted on the documentation, or if the function would take the normal as a parameter.

Hey -

Can you explain what you’re seeing and how you’re calling the FMath function? I tried to test this by creating multiple FVectors and then adding them to an array. Passing this array into PointsAreCoplanar returned true/false as expected based on the number/locations of the FVectors in the array. Can you post how you’re using the function so that I can make sure my setup matches yours.

Cheers

I’m not sure why the comment you posted isn’t showing but I wanted to ask you about it. Here is the original comment:

Have you tried with the three first
points aligned? This should return
false since the normal computed to
check coplanarity is obtained with the
three first points:

const FVector Normal =
FVector::CrossProduct(Points[2] -
Points[0], Points[1] -
Points[0]).GetSafeNormal();

How many elements are in the array? What are the values of each element? How does FVector Normal relate to the PointsAreCoplanar() call? What is the tolerance set to in the Coplanar call? With the following vectors in an array, PointsAreCoplanar() returns true when called:

Point1.Set(34, 45, 56);
Point2.Set(12, 23, 34);
Point3.Set(98, 87, 76);
Point4.Set(3, 4, 5);
Point5.Set(1, 2, 3);
Point6.Set(9, 8, 7);	
Point7.Set(512, 613, 734);
Point8.Set(98, 87, 76);

If I change the value of Point7 to (5112, 6113, 7134), the same call to PointsAreCoplanar will return false instead. Can you try using these values and let me know what result you get?

(I deleted my comment because I didn’t have time to test to make sure I was right) Now I confirme that this code returns true when it should return false:

TArray<FVector> Points;
Points.Add(FVector(0,0,0));
Points.Add(FVector(1,0,0));
Points.Add(FVector(2,0,0));
Points.Add(FVector(8,6,10));
UE_LOG(LogTemp, Warning, TEXT("Points are coplanar: %d"), FMath::PointsAreCoplanar(Points)); // returns true instead of false 

Again, this is due to the fact that the three first points are aligned, so the normal computed in PointsAreCoplanar() is equal to (0, 0, 0) and cannot be used to check coplanarity.

Again, this is the source code of FMath::PointsAreCoplanar().

Hey -

I want to apologize, I did not understand what you were saying at first. I thought you were reporting the function itself being broken. Now I understand you are referring to specifically when the points that define the plane are in a line (I missed that part initially). This is still not a bug as the first three points that are aligned do define a plane, however because they are aligned they actually form an infinite number of planes (rotated along the line of the first 3 points). This is why the function returns true with the fourth point. Regardless where the fourth point is located, it will still form a plane with the first three.

Cheers