v0.14.0
Loading...
Searching...
No Matches
sdf_hertz_3d.py
Go to the documentation of this file.
1import math
2import numpy as np
3
4R = 100 # radius of the indenter
5d = 0.01 # indentation depth
6
7xc = 0
8yc = 0
9zc = R
10
11def 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
14def 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
17def 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
20class Sphere:
21 def sDF(r, xc, yc, zc, x, y, z):
22 return np.sqrt((x - xc)**2 + (y - yc)**2 + (z - zc)**2) - r
23
24 def gradSdf(xc, yc, zc, x, y, z):
25 c_val_A = 1./np.sqrt((x-xc)**2 + (y-yc)**2 + (z-zc)**2)
26 return np.hstack([(c_val_A * (x-xc)).reshape((-1,1)), (c_val_A * (y-yc)).reshape((-1,1)), (c_val_A * (z-zc)).reshape((-1,1))])
27
28 def hessSdf(xc, yc, zc, x, y, z):
29 x, y, z = x-xc, y-yc, z-zc
30 denom = (x**2 + y**2 + z**2)**(3/2)
31 sqrt_denom = np.sqrt(x**2 + y**2 + z**2)
32 Hxx = -x**2/denom + 1/sqrt_denom
33 Hzx = -x*z/denom
34 Hxy = -x*y/denom
35 Hyy = -y**2/denom + 1/sqrt_denom
36 Hzy = -y*z/denom
37 Hzz = -z**2/denom + 1/sqrt_denom
38 # xx, yx, zx, yy, zy, zz
39 return np.hstack([Hxx.reshape((-1,1)), Hxy.reshape((-1,1)), Hzx.reshape((-1,1)), Hyy.reshape((-1,1)), Hzy.reshape((-1,1)), Hzz.reshape((-1,1))])
sDF(r, xc, yc, zc, x, y, z)
hessSdf(xc, yc, zc, x, y, z)
gradSdf(xc, yc, zc, x, y, z)
grad_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
hess_sdf(delta_t, t, x, y, z, tx, ty, tz, block_id)
Definition sdf.py:1