/// <summary> /// Calcuated as the exterior between adjacent faces. /// Result is in range [0 - 2Pi]. /// Assumes the given face normals are unitized. /// </summary>> public static double GetDihedralAngle <V, E, F>(this IHalfedge <V, E, F> hedge, Func <V, Vec3d> getPosition, Func <F, Vec3d> getNormal) where V : IHeVertex <V, E, F> where E : IHalfedge <V, E, F> where F : IHeFace <V, E, F> { Vec3d tangent = getPosition(hedge.End) - getPosition(hedge.Start); tangent.Unitize(); Vec3d x = getNormal(hedge.Face); Vec3d y = Vec3d.Cross(x, tangent); Vec3d d = getNormal(hedge.Twin.Face); double t = Math.Atan2(Vec3d.Dot(d, y), Vec3d.Dot(d, x)); t = (t < 0.0) ? t + SlurMath.TwoPI : t; // shift discontinuity to 0 return(SlurMath.Mod(t + Math.PI, SlurMath.TwoPI)); // add angle bw normals and faces }
/// <summary> /// Calcuated as the exterior between adjacent faces. /// Result is in range [0 - 2Pi]. /// Assumes the given face normals are unitized. /// </summary>> public static double GetDihedralAngle <V, E, F>(this IHalfedge <V, E, F> hedge, Func <V, Vec3d> getPosition, Func <F, Vec3d> getNormal) where V : IHeVertex <V, E, F> where E : IHalfedge <V, E, F> where F : IHeFace <V, E, F> { // TODO // refactor as per http://brickisland.net/DDGFall2017/2017/10/12/assignment-1-coding-investigating-curvature/ Vec3d tangent = getPosition(hedge.End) - getPosition(hedge.Start); tangent.Unitize(); Vec3d x = getNormal(hedge.Face); Vec3d y = Vec3d.Cross(x, tangent); Vec3d d = getNormal(hedge.Twin.Face); double t = Math.Atan2(Vec3d.Dot(d, y), Vec3d.Dot(d, x)); t = (t < 0.0) ? t + SlurMath.TwoPI : t; // shift discontinuity to 0 return(SlurMath.Mod(t + Math.PI, SlurMath.TwoPI)); // add angle bw normals and faces }