In [62]:
%reload_ext Cython
In [66]:
%%cython
import numpy as np
cimport numpy as np
import cython
class myclass(object):
def myfunct(self,object[double, ndim=1] V1, object[double, ndim=1] V2,object[double, ndim=1] V3, object[double, ndim=1] O,object[double, ndim=1] D):
cdef float EPSILON = 0.000001
e1 = np.subtract(V2,V1)
e2 = np.subtract(V3,V1)
P = np.cross(D, e2)
det = np.dot(e1, P)
if det > -EPSILON and det < EPSILON : return 0, 0
inv_det = float(1.0)/det
T = np.subtract(O, V1)
u = round(np.dot(T, P) * inv_det, 6)
if u < 0.0 or u > 1.0 : return 0, 0
Q = np.cross(T, e1)
v = round(np.dot(D, Q) * inv_det, 6)
if v < 0.0 or (u + v) > 1.0 : return 0, 0
t = np.dot(e2, Q) * inv_det
if t > EPSILON :
return t, det
return 0, 0
In [67]:
V1 = np.array([0.0,0.0,-1.0])
V2 = np.array([0.0,0.0,1.0])
V3 = np.array([0.0,1.0,0.0])
p0 = [-1.0,0.5,0.0]
p1 = [1.0,0.5,0.0]
O = np.array(p0)
D = np.subtract(p1,p0)
In [68]:
%%timeit -n1
s=myclass()
myfunct(V1, V2, V3, O, D)
#myfunct()
In [ ]:
In [ ]: