import maya.api.OpenMaya as Om
import maya.cmds as m
import maya.utils as u
def vectorTest_4i4ikov(v1,v2,v3):
a = Om.MVector(v1-v3).length()
b = Om.MVector(v2-v3).length()
c = Om.MVector(v2-v1).length()
k = (a*a - b*b)/(2*c*c) + 0.5
return v2*k+v1*(1-k)
def vectorTest_Dark(v1,v2,v3):
v21 = v2-v1
d = Om.MVector(v21).length()
return v1+(v3-v1)*v21*v21/(d*d)
import time
class new_Bench:
mera = time.time
#mera = time.clock
def __init__(self):
self.time=self.mera()
def reset(self):
self.__init__()
def get(self):
self.time = self.mera() - self.time
return self.time
v1 = Om.MVector(5.111 , -2.046, -1.956)
v2 = Om.MVector(-5.419 , -0.070 , -1.225)
v3 = Om.MVector( -0.246 , 0 , -6.764)
print '\n','-'*20,'check'
print 'Dark (vector):',vectorTest_Dark(v1,v2,v3)
print '4i4ikov (scalar):',vectorTest_4i4ikov(v1,v2,v3)
Bench = new_Bench()
N = 100000
print '\n','-'*20,'bench',N
Bench.reset()
for i in xrange(1,N): u.executeDeferred("vectorTest_Dark(v1/i,v2/i,v3/i)")
print 'Dark (vector):',Bench.get()
Bench.reset()
for i in xrange(1,N): u.executeDeferred("vectorTest_4i4ikov(v1/i,v2/i,v3/i)")
print '4i4ikov (scalar):',Bench.get()
Bench.reset()
for i in xrange(1,N): u.executeDeferred("vectorTest_Dark(v1/i,v2/i,v3/i)")
print 'Dark (vector):',Bench.get()
Bench.reset()
for i in xrange(1,N): u.executeDeferred("vectorTest_4i4ikov(v1/i,v2/i,v3/i)")
print '4i4ikov (scalar):',Bench.get()