def uniformPointInner(self): pointA, pointB = random.choices(self.segments, cum_weights=self.cumulativeLengths)[0] interpolation = random.random() x, y = averageVectors(pointA, pointB, weight=interpolation) if self.orientation is True: return OrientedVector(x, y, headingOfSegment(pointA, pointB)) else: return self.orient(Vector(x, y))
def directionAt(self, point): # TODO improve? median = self.medianPoints pt = np.array(point) # find closest point on median dists = np.linalg.norm(median - pt, axis=1) i, dist = min(enumerate(dists), key=lambda p: p[1]) # if at either end of median, use that direction if i == 0: x, y = median[:2] elif i == len(median)-1: x, y = median[-2:] else: # otherwise, pick which of the two directions to use based on # which side of the angle bisector we are on d1, d2 = median[i+1] - median[i], median[i-1] - median[i] d1 /= np.linalg.norm(d1) d2 /= np.linalg.norm(d2) bisector = d1 + d2 if pt[1] * bisector[0] - pt[0] * bisector[1] < 0: x, y = median[i-1], median[i] else: x, y = median[i], median[i+1] return headingOfSegment(x, y)