Last active
July 4, 2023 04:20
-
-
Save bicycle1885/c37ed1fd18bae6a61af6a05b293f3b05 to your computer and use it in GitHub Desktop.
Dihedral angle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Public Domain | |
using LinearAlgebra: cross, dot, norm | |
""" | |
dihedral(r1, r2, r3, r4) | |
Compute the dihedral angle of two planes defined by (`r1`, `r2`, `r3`) and | |
(`r2`, `r3`, `r4`). | |
Reference: https://en.wikipedia.org/wiki/Dihedral_angle | |
""" | |
function dihedral(r1, r2, r3, r4) | |
u1 = r2 - r1 | |
u2 = r3 - r2 | |
u3 = r4 - r3 | |
x = cross(u1, u2) | |
y = cross(u2, u3) | |
return atan(norm(u2) * dot(u1, y), dot(x, y)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment