示例#1
0
    def draw_vector(self, vector: Vector, starting_point: Point):
        # Flip y since 0 0 is at top
        unscaled_vector_to_draw = BridgeGUI.flip_vector_on_y(
            vector).get_unit_vector()

        vector_tail = Vector.from_point(self.scale_point(starting_point))
        vector_tip = unscaled_vector_to_draw * BridgeGUI.LENGTH_OF_VECTOR + vector_tail
        label_position = vector_tail + unscaled_vector_to_draw * BridgeGUI.LENGTH_TO_LABEL

        self.draw_line(vector_tail, vector_tip, arrow=True)
        self.draw_label(label_position, vector.get_magnitude().rescale(kN))
示例#2
0
    def calculate_member_forces(self):

        # Loop through every joint repeatedly.
        # At each joint look for member forces + external forces + joint load
        # In each component, verify if there's only one unknown_opposing_joints. Repeat in other component if solved
        # Repeat for other joints
        passes = 0
        calculated_joints = set()
        while passes < len(self.bridge.joints) * 2 and len(calculated_joints) < len(self.bridge.joints):
            for joint, joint_property in self.bridge.joints.items():
                if joint in calculated_joints:
                    continue

                sum_of_forces = Vector(0 * pq.N, 0 * pq.N)
                unknown_opposing_joints = []

                # Get forces in members
                for connected_joint in joint_property.connected_joints:
                    direction_vector = Vector.from_a_to_b(joint, connected_joint)
                    member_force = self.bridge.beams[Beam(joint, connected_joint)].member_force

                    if member_force is None:
                        unknown_opposing_joints.append(connected_joint)
                    else:
                        sum_of_forces += direction_vector.get_unit_vector() * member_force

                if joint_property.external_force is not None:
                    sum_of_forces += joint_property.external_force

                if len(unknown_opposing_joints) > 3:
                    continue

                # If all forces are known make sure sum is zero and you're done
                elif len(unknown_opposing_joints) == 0:
                    if sum_of_forces != Vector(0, 0):
                        print(f"ERROR: Sum of forces at joint, {joint}, is {sum_of_forces} not (0, 0).")
                    calculated_joints.add(joint)

                # If only one force make sure it's opposite to the current sum of forces.
                elif len(unknown_opposing_joints) == 1:
                    unknown_opposing_joint = unknown_opposing_joints[0]
                    direction_vector = Vector.from_a_to_b(joint, unknown_opposing_joint)

                    if sum_of_forces == Vector(0, 0):
                        self.bridge.beams[Beam(unknown_opposing_joint, joint)].member_force = 0 * pq.N
                    elif sum_of_forces.is_collinear(direction_vector):
                        self.bridge.beams[Beam(unknown_opposing_joint, joint)].member_force = sum_of_forces.cos_theta(
                            direction_vector) * sum_of_forces.get_magnitude() * -1
                    else:
                        print(
                            f"Error. Sum of forces ({sum_of_forces})"
                            f" is not in the same direction as the only unknown beam (dir: {direction_vector})"
                            f" for joint {joint}.")
                    calculated_joints.add(joint)

                elif len(unknown_opposing_joints) == 2:
                    unknown_joint_1 = unknown_opposing_joints.pop()
                    unknown_joint_2 = unknown_opposing_joints.pop()
                    unknown_force_1 = Vector.from_a_to_b(joint, unknown_joint_1)
                    unknown_force_2 = Vector.from_a_to_b(joint, unknown_joint_2)

                    if unknown_force_1.is_collinear(unknown_force_2):
                        continue

                    (force_1, force_2) = BridgeCalculator.solve_for_two_unknowns(sum_of_forces, unknown_force_1,
                                                                                 unknown_force_2)
                    self.bridge.beams[Beam(joint, unknown_joint_1)].member_force = force_1
                    self.bridge.beams[Beam(joint, unknown_joint_2)].member_force = force_2

                    calculated_joints.add(joint)

                elif len(unknown_opposing_joints) == 3:
                    unknown_joint_1 = unknown_opposing_joints.pop()
                    unknown_joint_2 = unknown_opposing_joints.pop()
                    unknown_joint_3 = unknown_opposing_joints.pop()
                    unknown_force_1 = Vector.from_a_to_b(joint, unknown_joint_1)
                    unknown_force_2 = Vector.from_a_to_b(joint, unknown_joint_2)
                    unknown_force_3 = Vector.from_a_to_b(joint, unknown_joint_3)

                    if unknown_force_1.is_collinear(unknown_force_2):
                        (force_1, force_3) = BridgeCalculator.solve_for_two_unknowns(sum_of_forces, unknown_force_1,
                                                                                     unknown_force_3)
                        self.bridge.beams[Beam(joint, unknown_joint_3)].member_force = force_3
                    elif unknown_force_2.is_collinear(unknown_force_3):
                        (force_1, force_2) = BridgeCalculator.solve_for_two_unknowns(sum_of_forces, unknown_force_1,
                                                                                     unknown_force_2)
                        self.bridge.beams[Beam(joint, unknown_joint_1)].member_force = force_1
                    elif unknown_force_3.is_collinear(unknown_force_1):
                        (force_1, force_2) = BridgeCalculator.solve_for_two_unknowns(sum_of_forces, unknown_force_1,
                                                                                     unknown_force_2)
                        self.bridge.beams[Beam(joint, unknown_joint_2)].member_force = force_2

            passes += 1