v0.14.0
sdf_flat.py
Go to the documentation of this file.
1 import math
2 import numpy as np
3 
4 R = 100 # radius of the indenter
5 d = 1 # indentation depth
6 
7 xc = 0
8 yc = 0
9 zc = 0
10 
11 def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
12 
13  if block_id == -1:
14  return np.ones_like(x)
15 
16  return zPlane.sDF(xc, yc, zc - d * t, x, y, z)
17 
18 def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
19  if block_id == -1:
20  zeros = np.zeros_like(x)
21  zeros = zeros.reshape((-1,1))
22  grad_array = np.hstack([zeros, zeros, zeros])
23  return grad_array
24 
25  return zPlane.gradSdf(xc, yc, zc - d * t, x, y, z)
26 
27 def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
28  if block_id == -1:
29  zeros = np.zeros_like(x)
30  zeros = zeros.reshape((-1,1))
31  hess_array = np.hstack([zeros, zeros, zeros, zeros, zeros, zeros])
32  # xx, yx, zx, yy, zy, zz
33  return hess_array
34 
35  return zPlane.hessSdf(xc, yc, zc - d * t, x, y, z)
36 
37 class Sphere:
38  def sDF(r, xc, yc, zc, x, y, z):
39  dx = np.subtract(x, xc)
40  dy = np.subtract(y, yc)
41  dz = np.subtract(z, zc)
42  a = dx**2 + dy**2 + dz**2
43  gap = np.sqrt(a) - r
44  return gap
45 
46  def gradSdf(xc, yc, zc, x, y, z):
47  a = (x-xc)**2 + (y-yc)**2 + (z-zc)**2
48  c_val = np.sqrt(a)
49  c_val_A = 1./c_val
50  c_val_dx = c_val_A * (x-xc)
51  c_val_dy = c_val_A * (y-yc)
52  c_val_dz = c_val_A * (z-zc)
53 
54  c_val_dx = c_val_dx.reshape((-1,1))
55  c_val_dy = c_val_dy.reshape((-1,1))
56  c_val_dz = c_val_dz.reshape((-1,1))
57  grad_array = np.hstack([c_val_dx,c_val_dy,c_val_dz])
58  return grad_array
59 
60  def hessSdf(xc, yc, zc, x, y, z):
61  x = x-xc
62  y = y-yc
63  z = z-zc
64  Hxx = -x**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
65  Hzx = -x*z/(x**2 + y**2 + z**2)**(3/2)
66  Hxy = -x*y/(x**2 + y**2 + z**2)**(3/2)
67  Hyy = -y**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
68  Hzy = -y*z/(x**2 + y**2 + z**2)**(3/2)
69  Hzz = -z**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
70  # xx, yx, zx, yy, zy, zz
71  Hxx = Hxx.reshape((-1,1))
72  Hzx = Hzx.reshape((-1,1))
73  Hxy = Hxy.reshape((-1,1))
74  Hyy = Hyy.reshape((-1,1))
75  Hzy = Hzy.reshape((-1,1))
76  Hzz = Hzz.reshape((-1,1))
77  hess_array = np.hstack([Hxx, Hxy, Hzx, Hyy, Hzy, Hzz])
78 
79  return hess_array
80 
81 
82 class zPlane:
83  def sDF(xc, yc, zc, x, y, z):
84  return zc - z
85 
86  def gradSdf(xc, yc, zc, x, y, z):
87  dx = np.zeros_like(x)
88  dy = np.zeros_like(y)
89  dz = np.ones_like(z)
90  dx = dx.reshape((-1,1))
91  dy = dy.reshape((-1,1))
92  dz = dz.reshape((-1,1))
93  grad_array = np.hstack([dx, dy, -dz])
94  return grad_array
95 
96  def hessSdf(xc, yc, zc, x, y, z):
97  zeros = np.zeros_like(x)
98  zeros = zeros.reshape((-1,1))
99 
100  hess_array = np.hstack([zeros, zeros, zeros, zeros, zeros, zeros])
101 
102  # xx, yx, zx, yy, zy, zz
103  return hess_array
sdf_flat.zPlane.hessSdf
def hessSdf(xc, yc, zc, x, y, z)
Definition: sdf_flat.py:96
sdf_flat.Sphere.sDF
def sDF(r, xc, yc, zc, x, y, z)
Definition: sdf_flat.py:38
sdf_flat.zPlane.gradSdf
def gradSdf(xc, yc, zc, x, y, z)
Definition: sdf_flat.py:86
sdf_flat.zPlane.sDF
def sDF(xc, yc, zc, x, y, z)
Definition: sdf_flat.py:83
sdf_flat.Sphere
Definition: sdf_flat.py:37
sdf_flat.Sphere.hessSdf
def hessSdf(xc, yc, zc, x, y, z)
Definition: sdf_flat.py:60
sdf_flat.sdf
def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_flat.py:11
sdf_flat.grad_sdf
def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_flat.py:18
sdf_flat.hess_sdf
def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_flat.py:27
sdf_flat.zPlane
Definition: sdf_flat.py:82
sdf_flat.Sphere.gradSdf
def gradSdf(xc, yc, zc, x, y, z)
Definition: sdf_flat.py:46