Example #1
0
 def _is_interior(self, Q, o, lc):
     if self.dim == 1:
         v1 = self.vertices[0].as_np_array()
         v2 = self.vertices[1].as_np_array()
         v1, v2 = v1 - o, v2 - o
         v1, v2 = np.dot(Q, v1), np.dot(Q, v2)
         return v1 <= lc <= v2
     elif self.dim == 2:
         v1 = self.vertices[0].as_np_array()
         v2 = self.vertices[1].as_np_array()
         v3 = self.vertices[2].as_np_array()
         v1, v2, v3 = v1 - o, v2 - o, v3 - o
         v1, v2, v3 = np.dot(Q, v1), np.dot(Q, v2), np.dot(Q, v3)
         return orient2d(v1, v2, lc) >= 0 \
                 and orient2d(v2, v3, lc) >= 0 \
                 and orient2d(v3, v1, lc) >= 0
     elif self.dim == 3:
         v1 = self.vertices[0].as_np_array()
         v2 = self.vertices[1].as_np_array()
         v3 = self.vertices[2].as_np_array()
         v4 = sefl.vertices[3].as_np_array()
         v1, v2 = v1 - o, v2 - o
         v3, v3 = v3 - o, v4 - o
         v1, v2 = np.dot(Q, v1), np.dot(Q, v2)
         v3, v4 = np.dot(Q, v3), np.dot(Q, v4)
         return orient3d(v1, v2, v3, lc) >= 0 \
                 and orient3d(v1, v3, v4, lc) >= 0 \
                 and orient3d(v1, v4, v2, lc) >= 0 \
                 and orient3d(v2, v4, v3, lc) >= 0
     else:
         raise Exception, 'Operation _is_interior only supports simplices of dimension 1-3.'
Example #2
0
 def _orient_positively(self):
     if self.dim == 2:
         v1 = self.vertices[0].as_np_array()
         v2 = self.vertices[1].as_np_array()
         v3 = self.vertices[2].as_np_array()
         if orient2d(v1, v2, v3) < 0:
             self.vertices[1], self.vertices[2] = self.vertices[2], self.vertices[1]
     elif self.dim == 3:
         v1 = self.vertices[0].as_np_array()
         v2 = self.vertices[1].as_np_array()
         v3 = self.vertices[2].as_np_array()
         v4 = self.vertices[3].as_np_array()
         if orient3d(v1, v2, v3, v4) < 0:
             self.vertices[2], self.vertices[3] = self.vertices[3], self.vertices[2]
     elif self.dim >= 4:
         A = np.array([v.as_np_array() for v in self.vertices])
         one_col = np.ones((len(self.vertices), 1))
         A = np.append(A, one_col, 1)
         if linalg.det(A) < 0:
             self.vertices[-2], self.vertices[-1] = self.vertices[-1], self.vertices[-2]
Example #3
0
def CCW(a, b, c):
# a = tuple(a); b = tuple(b); c = tuple(c);

 print 'CCW: a:', a, 'b:', b,'c:', c 
 return True if (orient2d(a,b,c) > 0) else False
Example #4
0
def height(a, b, c):
    base = a.distance(b)
    if base > 0:
        height = abs(orient2d(a, b, c)) / base
        return round(height * 2.) * .5
Example #5
0
def CCW(a, b, c):
 return True if (orient2d(a,b,c) > 0) else False
Example #6
0
from predicates import orient2d, incircle, orient3d, insphere

import numpy as np

pa = np.array([0, 0], dtype=np.float64)
pb = np.array([0, 1], dtype=np.float64)
pc = np.array([0.5, 0.5], dtype=np.float64)
pd = np.array([-0.5, 0.5], dtype=np.float64)

print orient2d(pa, pb, pc)
print orient2d(pa, pc, pb)

print incircle(pa, pb, pc, pd)
print incircle(pa, pb, pd, pc)

pa = np.array([0, 0, 0], dtype=np.float64)
pb = np.array([0, 1, 0], dtype=np.float64)
pc = np.array([0, 0, 1], dtype=np.float64)
pd = np.array([10, 0, 0], dtype=np.float64)

print orient3d(pa, pb, pc, pd)
print orient3d(pa, pb, pd, pc)

print insphere(pa, pb, pc, pd)
print insphere(pa, pb, pd, pc)