def _LF_ij(self, i, j, epsilon): bottom, top = 0, 1 bp = Point([bottom * x + (1 - bottom) * y for x, y in zip(self.Q[j + 1], self.Q[j])]) tp = Point([top * x + (1 - top) * y for x, y in zip(self.Q[j + 1], self.Q[j])]) d, loop = bp.dist_sq(self.P[i]), 1 prime = self.epsDot(self.Q[j + 1], self.Q[j], self.P[i], bottom) while d != epsilon and loop < 52: if d < epsilon and bottom == 0: loop = 52 else: bottom = self._editLB(bottom, loop, d, epsilon, prime) loop += 1 bp = Point([bottom * x + (1 - bottom) * y for x, y in zip(self.Q[j + 1], self.Q[j])]) prime = self.epsDot(self.Q[j + 1], self.Q[j], self.P[i], bottom) d = bp.dist_sq(self.P[i]) if abs(d - epsilon) > 0.00000000002 and bottom != 0: bottom = 2 d, loop = tp.dist_sq(self.P[i]), 1 prime = self.epsDot(self.Q[j + 1], self.Q[j], self.P[i], top) while d != epsilon and loop < 52: if d < epsilon and top == 1: loop = 52 else: top = self._editRT(top, loop, d, epsilon, prime) loop += 1 tp = Point([top * x + (1 - top) * y for x, y in zip(self.Q[j + 1], self.Q[j])]) prime = self.epsDot(self.Q[j + 1], self.Q[j], self.P[i], top) d = tp.dist_sq(self.P[i]) if abs(d - epsilon) > 0.00000000002 and top != 1: top = 2 return (bottom, top)
def _BF_ij(self, i, j, epsilon): left, right = 0, 1 lp = Point([left * x + (1-left) * y for x, y in zip(self.P[i+1], self.P[i])]) rp = Point([right * x + (1-right) * y for x, y in zip(self.P[i+1], self.P[i])]) d, loop = lp.dist_sq(self.Q[j]), 1 prime = self.epsDot(self.P[i+1], self.P[i], self.Q[j], left) while d != epsilon and loop < 52: if d < epsilon and left == 0: loop = 52 else: left = self._editLB(left, loop, d, epsilon, prime) loop += 1 lp = Point([left * x + (1 - left) * y for x, y in zip(self.P[i + 1], self.P[i])]) prime = self.epsDot(self.P[i + 1], self.P[i], self.Q[j], left) d = lp.dist_sq(self.Q[j]) if abs(d - epsilon) > 0.00000000002 and left != 0: left = 2 d, loop = rp.dist_sq(self.Q[j]), 1 prime = self.epsDot(self.P[i + 1], self.P[i], self.Q[j], right) while d != epsilon and loop < 52: if d < epsilon and right == 1: loop = 52 else: right = self._editRT(right, loop, d, epsilon, prime) loop += 1 rp = Point([right * x + (1-right) * y for x,y in zip(self.P[i+1], self.P[i])]) prime = self.epsDot(self.P[i + 1], self.P[i], self.Q[j], right) d = rp.dist_sq(self.Q[j]) if abs(d - epsilon) > 0.00000000002 and right != 1: right = 2 return (left, right)
def test_3D_point_sq_dist(self): coords1 = [-1, 2, 3] coords2 = [4, 0, -3] coords3 = [7, 4, 3] coords4 = [17, 6, 2] p1 = Point(coords1, 0) p2 = Point(coords2, 0) p3 = Point(coords3, 0) p4 = Point(coords4, 0) self.assertEqual(p1.dist_sq(p2), 65) self.assertEqual(p1.dist_sq(p1), 0.0) self.assertEqual(p3.dist_sq(p4), 105)
def test_2D_point_sq_dist(self): coords1 = [-7, -4] coords2 = [17, 6] coords3 = [3, 4] coords4 = [0, 0] p1 = Point(coords1) p2 = Point(coords2) p3 = Point(coords3) p4 = Point(coords4) self.assertEqual(p1.dist_sq(p2), 676.0) self.assertEqual(p1.dist_sq(p1), 0.0) self.assertEqual(p3.dist_sq(p4), 25.0)
def _critB(self, i, j): dirv = Point([x - y for x, y in zip(self.Q[j + 1], self.Q[j])]) mag = math.sqrt(dot(dirv, dirv)) n = Point([x / mag for x in dirv]) qp = Point([w - z for w, z in zip(self.Q[j], self.P[i])]) c = dot(n, qp) v = Point([c * x for x in n]) return qp.dist_sq(v)
def _critCQ(self, k, l): p = Point([0.5 * x + 0.5 * y for x, y in zip(self.Q[k], self.Q[l])]) n = Point([y - x for x, y in zip(self.Q[k], self.Q[l])]) d = dict() B = getBasis(p, n) for x in range(len(self.P) - 1): M, M2 = getMatrix(B, self.P[x]), getMatrix(B, self.P[x+1]) d1, d2 = getMatrixDeterminant(M), getMatrixDeterminant(M2) if d1 * d2 <= 0: d1, d2 = abs(d1), abs(d2) if d1 - d2 == 0: q = Point([0.5 * x + 0.5 * y for x, y in zip(self.P[x], self.P[x+1])]) else: q = Point([(d2 * x + d1 * y)/(d1 + d2) for x, y in zip(self.P[x], self.P[x+1])]) d[x] = q.dist_sq(self.Q[k]) return d