Download

Angle between two surfaces

Hey guys, how do you calculate the angle between two surfaces? This is not the angle between the two normals, else the angle for a V and A shape (reversed-V, see below) would be the same. Thanks.

/\ \ /
/ \ /

Hello,
“surfaces” you mean planes? Angle between planes is the same as angle between their normals. Look ad the picture http://geomalgorithms.com/Pic_2-planes.gif. There is intersection line and on the left you can se V shape and on the left A shape.

If alpha is the angle between the two sufraces in V shape (or planes if you prefer), then 180+(180-alpha) is the angle between the two surfaces on the A shape. However the normal angle calculation will always return alpha for both shapes. I need to determine if the angle is closed or open, normals don’t tell that.

You want the 360 based angle between two 3D vectors. It’s not that simple but not overly complicated either.
I’m new to UE but here are some links that may be inspiring:
Based off vectors only: Deriving angles from 0 to 360 from Dot Product. - OpenGL - Khronos Forums
Based off quaternions: Getting 360 angle between two 3d vectors for Unity3D. · GitHub
Of course you’d have to do some work :smiley:

Have you tried the | operator which does the dot product between two planes?



float AngleBetweenTwoPlanes(const FPlane& A, const FPlane& B)
{
   return FMath::Acos(A | B); // Should be in radians, convert to degrees if needed.
}


Here’s somethingstraightforward but smelly… I don’t trust it does what it says but who knows? If you try it please let to be known if it works or not.

Thanks a lot guys! I have experimented with the various methods. The FPlane one didn’t work for me, maybe I didn’t use it properly. Finally, here is what I am doing:

  • I get plane parallel vectors (v1 and v2) from the normals (which are my inputs as come from a line trace) by rotating the normals by 90 deg.
  • I calculate the angle between each plane and an up vector (in my case the up vector of an actor) using cos(angle)=dotProduct(v1,v2)
  • the full angle between the two planes is the sum of the two angles found at the above step. In fact for my needs I am only interrested into each separate angle (with the up vector).