v0.14.0
sdf_sphere.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 = 0.01 # indentation depth
6 
7 xc = 0
8 yc = 0
9 zc = R
10 
11 def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
12  return Sphere.sDF(R, xc, yc, zc - d * t, x, y, z)
13 
14 def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
15  return Sphere.gradSdf(xc, yc, zc - d * t, x, y, z)
16 
17 def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id):
18  return Sphere.hessSdf(xc, yc, zc - d * t, x, y, z)
19 
20 class Sphere:
21  def sDF(r, xc, yc, zc, x, y, z):
22  dx = np.subtract(x, xc)
23  dy = np.subtract(y, yc)
24  dz = np.subtract(z, zc)
25  a = dx**2 + dy**2 + dz**2
26  gap = np.sqrt(a) - r
27  return gap
28 
29  def gradSdf(xc, yc, zc, x, y, z):
30  a = (x-xc)**2 + (y-yc)**2 + (z-zc)**2
31  c_val = np.sqrt(a)
32  c_val_A = 1./c_val
33  c_val_dx = c_val_A * (x-xc)
34  c_val_dy = c_val_A * (y-yc)
35  c_val_dz = c_val_A * (z-zc)
36 
37  c_val_dx = c_val_dx.reshape((-1,1))
38  c_val_dy = c_val_dy.reshape((-1,1))
39  c_val_dz = c_val_dz.reshape((-1,1))
40  grad_array = np.hstack([c_val_dx,c_val_dy,c_val_dz])
41  return grad_array
42 
43  def hessSdf(xc, yc, zc, x, y, z):
44  x = x-xc
45  y = y-yc
46  z = z-zc
47  Hxx = -x**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
48  Hzx = -x*z/(x**2 + y**2 + z**2)**(3/2)
49  Hxy = -x*y/(x**2 + y**2 + z**2)**(3/2)
50  Hyy = -y**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
51  Hzy = -y*z/(x**2 + y**2 + z**2)**(3/2)
52  Hzz = -z**2/(x**2 + y**2 + z**2)**(3/2) + 1/np.sqrt(x**2 + y**2 + z**2)
53  # xx, yx, zx, yy, zy, zz
54  Hxx = Hxx.reshape((-1,1))
55  Hzx = Hzx.reshape((-1,1))
56  Hxy = Hxy.reshape((-1,1))
57  Hyy = Hyy.reshape((-1,1))
58  Hzy = Hzy.reshape((-1,1))
59  Hzz = Hzz.reshape((-1,1))
60  hess_array = np.hstack([Hxx, Hxy, Hzx, Hyy, Hzy, Hzz])
61 
62  return hess_array
63 
64 
65 
66 
67 
sdf_sphere.Sphere
Definition: sdf_sphere.py:20
sdf_sphere.Sphere.hessSdf
def hessSdf(xc, yc, zc, x, y, z)
Definition: sdf_sphere.py:43
sdf_sphere.grad_sdf
def grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_sphere.py:14
sdf_sphere.Sphere.sDF
def sDF(r, xc, yc, zc, x, y, z)
Definition: sdf_sphere.py:21
sdf_sphere.Sphere.gradSdf
def gradSdf(xc, yc, zc, x, y, z)
Definition: sdf_sphere.py:29
sdf_sphere.hess_sdf
def hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_sphere.py:17
sdf_sphere.sdf
def sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition: sdf_sphere.py:11