Calculate the back side | Babylon.js Playground (babylonjs.com)
I have tried using the distance between vectors and planes to calculate. But in some cases, this may result in calculation errors(Activate PG 32 lines)
How should the position of this door be calculated when the plane is back-to-back with an associated PG
Calculate the back side2 | Babylon.js Playground (babylonjs.com)
I have spent several days calculating this (My math is terrible)
Hello @lingliyi , how are you doing?
So, my understanding is that you have those two planes and you want to know the distance between them, right?
No, no, no, I need these two planes back to back
Let me know if this is what you want:
Calculate the back side2 | Babylon.js Playground (babylonjs.com)
I just created the exactly same mesh twice and called flipFaces() in one of them.
Wow, flipping normals like this is new to me. This answer is getting close to what I want, but this method does not check which plane should be flipped, which can lead to a situation where the planes are facing each other
Hello,
you can check the normal of both planes, and determine if they are facing the same or opposite direction using dot product, I updated the playground for you. the function flips one of the planes if they are facing opposite direction
cheers!
cheers
But this is not right, we should only be able to see one plane from both sides(Mesh.FRONTSIDE ). Now we can only see two planes from one side
My guess is the flip that is farthest from this normal vector
Calculate the back side2 | Babylon.js Playground (babylonjs.com)
Is this the result you want?
Oh I must have read your question wrong
you want the planes to be in front of each other and not side to side like you showed in your example?
Yes ,But I hope to flip a certain plane through calculation
This is the effect https://playground.babylonjs.com/#1YTZAC#263
Because of the use of rotation.y, it is not clear on which plane flipFaces should be used.
Who can help me ?
What you can do, assuming both planes are on the same side of the camera and parallel:
- Look at where the camera is in relation to the planes. The camera will either be on the “positive” side, or on the “negative” side. You can tell this by using the camera position in the plane equation and looking at the sign of the result.
- Now you can find the position of a point of plane 1 relative to plane 2, using the same calculation. This point will be either on the “positive” or “negative” side of plane 2. If this sign is the same as in step 1, this means that plane 1 is closer to the camera than plane 2, because this point (and therefore the whole plane, since planes are assumed to be parallel) and the camera are on the same side of plane 2.
Here’s a PG that implements it: