def diagonalize_curvature(cls, old_u, old_v, ku, kuv, kv, new_norm):
"""Given a curvature tensor, diagonalize to find principal directions and curvatures."""
# Rotate old coord system to be normal to new.
r_old_u, r_old_v = cls.rotate_coord_sys(old_u, old_v, new_norm)
c = 1
s = 0
tt = 0
if not math.isclose(kuv, 0):
# Jacobi rotation to diagonalize.
h = 0.5 * (kv - ku) / kuv
if h < 0:
tt = 1 / (h - math.sqrt(1 + h*h))
else:
tt = 1 / (h + math.sqrt(1 + h*h))
c = 1 / math.sqrt(1 + tt*tt)
s = tt * c
# Compute principal curvatures.
k1 = ku - tt * kuv
k2 = kv + tt * kuv
# Compute principal directions.
if abs(k1) >= abs(k2):
pdir1 = c * r_old_u - s * r_old_v
else:
k1, k2 = k2, k1 # swap
pdir1 = s * r_old_u + c * r_old_v
pdir2 = np.cross(new_norm, pdir1)
# Return all the things.
return pdir1, pdir2, k1, k2
评论列表
文章目录