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 directional_test(shape1, shape2, direction): """ Computes the distance vector from the center of the shapes and returns it with a boolean indicating the direction of the vector """ center_distance = tools.calculate_absolute_distance_center(shape1, shape2)[direction] #side_distance = tools.calculate_absolute_distance_sides(shape1, shape2, direction) if center_distance > 0: return (center_distance, False) else: return (center_distance, True)
def intersect_test(shape1, shape2): """ Checks to see if the distance vector between the center and the distance vector between the sides of two shapes are in the opposite direction """ counter = 0 for side in xrange(3): if tools.calculate_absolute_distance_sides(shape1, shape2, side)*tools.calculate_absolute_distance_center(shape1, shape2)[side] <= 0: counter += 1 if counter > 2: return True else: return False
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