Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1r""" 

2.. role:: raw-math(raw) :format: latex html 

3 

4-------------------- 

5Curvature 

6-------------------- 

7 

8In MembraneCurvature, we calculate Gaussian and mean curvature from a cloud of points. 

9 

10Gaussian curvature is defined by 

11 

12.. math:: K = \frac{\partial_{xx}\partial_{yy}-\partial_{xy}^2} 

13 {(1+\partial_x^2+\partial_y^2)^2}. 

14 

15Mean curvature is defined by 

16 

17.. math:: H = 

18 \frac{(1+\partial_x^2)\partial_{yy}+(1+\partial_y^2)\partial_{xx}-2\partial_x\partial_y\partial_{xy}} 

19 {2(1+\partial_x^2+\partial_y^2)^{3/2}}. 

20 

21 

22Notes 

23--------- 

24 

25Since the mean curvature calculates the arithmetic mean of two 

26principal curvatures, the default units of :math:`H` are Å\ :sup:`-1`. 

27On the other hand, Gaussian curvature calculates the geometric mean of the 

28two principal curvatures. Therefore, the default units of :math:`K` are Å\ :sup:`-2`. 

29In general, units of mean curvature are [length] :sup:`-1`, 

30and units of Gaussian curvature are [length] :sup:`-2`. 

31 

32.. warning:: 

33 

34 Numpy cannot calculate the gradient for arrays with inner array of 

35 `length==1` unless `axis=0` is specified. Therefore in the functions here included 

36 for mean and Gaussian curvature, shape of arrays must be at least (2,2). 

37 In general, to calculate a numerical gradients shape of arrays must be >=(`edge_order` + 

38 1). 

39 

40 

41Functions 

42--------- 

43 

44""" 

45 

46import numpy as np 

47 

48 

49def gaussian_curvature(Z): 

50 """ 

51 Calculate gaussian curvature from Z cloud points. 

52 

53 

54 Parameters 

55 ---------- 

56 Z: np.ndarray. 

57 Multidimensional array of shape (n,n). 

58 

59 

60 Returns 

61 ------- 

62 K : np.ndarray. 

63 The result of gaussian curvature of Z. Returns multidimensional 

64 array object with values of gaussian curvature of shape `(n, n)`. 

65 

66 """ 

67 

68 Zy, Zx = np.gradient(Z) 

69 Zxy, Zxx = np.gradient(Zx) 

70 Zyy, _ = np.gradient(Zy) 

71 

72 K = (Zxx * Zyy - (Zxy ** 2)) / (1 + (Zx ** 2) + (Zy ** 2)) ** 2 

73 

74 return K 

75 

76 

77def mean_curvature(Z): 

78 """ 

79 Calculates mean curvature from Z cloud points. 

80 

81 

82 Parameters 

83 ---------- 

84 Z: np.ndarray. 

85 Multidimensional array of shape (n,n). 

86 

87 

88 Returns 

89 ------- 

90 H : np.ndarray. 

91 The result of gaussian curvature of Z. Returns multidimensional 

92 array object with values of gaussian curvature of shape `(n, n)`. 

93 

94 """ 

95 

96 Zy, Zx = np.gradient(Z) 

97 Zxy, Zxx = np.gradient(Zx) 

98 Zyy, _ = np.gradient(Zy) 

99 

100 H = (1 + Zx**2) * Zyy + (1 + Zy**2) * Zxx - 2 * Zx * Zy * Zxy 

101 H = H / (2 * (1 + Zx**2 + Zy**2)**(1.5)) 

102 

103 return H