-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
30 lines (24 loc) · 826 Bytes
/
example.py
File metadata and controls
30 lines (24 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import autodiffPythonCpp as apc
import sympy
import numpy as np
def sigmoid(x, scale, shift=0.5):
return 1. / (1. + sympy.exp(-1. * scale * (x - shift)))
def compute_t(P):
P0 = P[:3]
P1 = P[3:6]
P2 = P[6:9]
t = -1 * (((P1-P0).dot(P2 - P1)) / apc.norm(P2 - P1) ** 2)
return sigmoid(t, 5.) # sigScale
def computeClosestPointOnLine(P):
P1 = P[3:6]
P2 = P[6:9]
return P1 + (P2 - P1) * compute_t(P)
def compute_D(P, props):
P0 = P[:3]
return apc.norm(P0 - computeClosestPointOnLine(P)) - props[0] - props[1]
# create a numpy array of symbols for both P and props
P = np.array(sympy.symbols('P:9'))
props = np.array(sympy.symbols('props:2'))
func = compute_D(P, props)
# call the generator
apc.create_header_source_files(func, P, props, 9, "sphere_capsule", "CodeGen_SphereCapsule")