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--------- 

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

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

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

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

281). 

29 

30 

31Functions 

32--------- 

33 

34""" 

35 

36import numpy as np 

37 

38 

39def gaussian_curvature(Z): 

40 """ 

41 Calculate gaussian curvature from Z cloud points. 

42 

43 

44 Parameters 

45 ---------- 

46 Z: np.ndarray. 

47 Multidimensional array of shape (n,n). 

48 

49 

50 Returns 

51 ------- 

52 K : np.ndarray. 

53 The result of gaussian curvature of Z. Returns multidimensional 

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

55 

56 """ 

57 

58 Zy, Zx = np.gradient(Z) 

59 Zxy, Zxx = np.gradient(Zx) 

60 Zyy, _ = np.gradient(Zy) 

61 

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

63 

64 return K 

65 

66 

67def mean_curvature(Z): 

68 """ 

69 Calculates mean curvature from Z cloud points. 

70 

71 

72 Parameters 

73 ---------- 

74 Z: np.ndarray. 

75 Multidimensional array of shape (n,n). 

76 

77 

78 Returns 

79 ------- 

80 H : np.ndarray. 

81 The result of gaussian curvature of Z. Returns multidimensional 

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

83 

84 """ 

85 

86 Zy, Zx = np.gradient(Z) 

87 Zxy, Zxx = np.gradient(Zx) 

88 Zyy, _ = np.gradient(Zy) 

89 

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

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

92 

93 return H