Why is Plane.isFrontFacingTo negated?

I find isFrontFacingTo counter intuitive. Shouldn’t

myPlane.isFrontFacingTo(myPlane.normal, 0)

return true since the plane clearly is facing in the direction of its normal?

This sentence in the docs make no sense to me:
True is the vector “direction” is the same side than the plane normal.

adding @PirateJC our doc master

Maybe the code will be clearer?

And actually by looking at the code I feel like there is a bug
it should return dot > epsilon right?

I think the current code is fine only if:

  • normal and direction are normalized (but it is not enforced in the doc / code - maybe the plane normal property is stored normalized?)
  • epsilon is a number just bigger than -1, that is something like -0.99 (but it should be explained in the doc)

I think isFrontFacingTo aim is to detect if the plane normal and the direction are opposite vectors (so we can say that “the plane is facing the given direction”), so if their angle is ~180°, meaning cos(angle) = dot = -1.

yes but for some reason I could expect epsilon to be 0 and in this case the code is wrong…

I think we should have it to behave correctly with 0 right?

Yes, I think something like dot <= -1 + epsilon would be better, as epsilon would need to be a small value just above 0, as everyone expects from a well-behaved epsilon.

yeah but the function name is FrontFacingTo, so I would expect that two vectors pointing the same direction will return true, right?
In this case the dot will be 1, correct?

Indeed, but it is a method of the plane class.

If a plane is front facing a direction, for me it means its normal is directly opposite to the direction we want to check.

Say the plane is perpendicular to our view direction, so lies in x/y and its normal is (0,0,-1) (if the normal were (0,0,1) it would be a back face and not visible). The view direction is (0,0,1), so the dot product is -1. In this configuration, I would say the plane is front facing the view direction.

ok that works for me ;D

Thanks @Evgeni_Popov for the clarification. It’s what I suspected. I think it’s a documentation issue as the current description is ambiguous:

Checks if the plane is facing a given direction

It should really say

Checks if the plane’s normal is pointing in the opposite direction of the given vector.

For me:

Checks if the plane is facing a given direction

is synonymous with:

Checks if the plane’s normal is pointing in the opposite direction of the given vector.

To make things clearer, I have added both to the doc:

I didn’t perform the change dot <= -1 + epsilon to avoid a breaking change (but I have explained which value epsilon should have with the current code to make things work).

2 Likes