def far_test(shape1, shape2, membership = 0): """ Checks to see if the distance is large enough between two shapes to determine they are far from each other, estimating the possible maximum distance between them as a baseline """ xs = [vertex[0] for vertex in shape1.scene_bounding_box] ys = [vertex[1] for vertex in shape1.scene_bounding_box] zs = [vertex[2] for vertex in shape1.scene_bounding_box] corners = [(x,y,z) for x in xs for y in ys for z in zs] distances = [tools.calculate_length(((shape1.location[0]-corner[0]), (shape1.location[1]-corner[1]), (shape1.location[2]-corner[2]))) for corner in corners] maximum_distance = max(distances) distance = tools.calculate_length(tools.calculate_absolute_distance_center(shape1, shape2)) relative_distance = float(distance)/maximum_distance value = far_value(relative_distance) #print shape1.name, value, shape2.name if membership == 1: return value if membership == 2: return near_value(relative_distance) if value > acceptable_threshold: return True else: return False """
def fill_vectors(self): """ Keeps a vector from the center of two shapes with the shape information, and the distance """ for shape in self.shapes: for shape2 in self.shapes: if shape != shape2: vector = tools.calculate_absolute_distance_center(shape, shape2) distance = tools.calculate_length(vector) self.vectors.append((shape,shape2,shape.name, shape2.name, vector,distance,shape.bounding_box[1][1]-shape.bounding_box[0][1]))
def contact_test(shape1, shape2): """ Checks to see if two shapes are near enough to be called adjacent by comparing the distance from the center and their size """ # Needs work return False sides1 = [] for index in xrange(2): sides1.append(shape1.bounding_box[1][index] - shape1.bounding_box[0][index]) sides2 = [] for index in xrange(2): sides2.append(shape2.bounding_box[1][index] - shape2.bounding_box[0][index]) side1 = min(sides1) side2 = min(sides2) side = min([side1, side2]) distance = tools.calculate_length(tools.calculate_absolute_distance_center(shape1, shape2)) num_shape1s_in_distance = math.fabs(float(distance) / side) if num_shape1s_in_distance <= 1.5 and not intersect_test(shape1, shape2): return True else: return False