def test_GIVEN_movement_along_z_WHEN_set_position_relative_to_beam_to_10_THEN_position_is_at_10_along_intercept(
            self):
        movement = LinearMovementCalc(PositionAndAngle(0, 10, 0))
        beam_intercept = Position(0, 10)
        beam = PositionAndAngle(0, 10, 270)
        dist = 10

        movement.set_distance_relative_to_beam(beam, dist)
        result = movement.position_in_mantid_coordinates()

        assert_that(
            result,
            is_(position(Position(beam_intercept.y, beam_intercept.z + dist))))
    def test_GIVEN_movement_45_to_z_at_beam_along_z_WHEN_z_of_movement_axis_changes_THEN_position_is_new_z(
            self):
        y = 0
        z = 7
        z_offset = 9
        movement = LinearMovementCalc(PositionAndAngle(y, z, 45))
        beam = PositionAndAngle(y, 0, 0)

        result = movement.calculate_interception(beam)
        assert_that(result, is_(position(Position(y, z))))

        movement.offset_position_at_zero(Position(0, z_offset))

        result = movement.calculate_interception(beam)
        assert_that(result, is_(position(Position(y, z + z_offset))))
    def test_GIVEN_movement_perp_to_z_at_beam_angle_45_WHEN_z_of_movement_axis_changes_THEN_position_is_as_expected(
            self):
        y = 0
        z = 7
        z_offset = 9
        movement = LinearMovementCalc(PositionAndAngle(y, z, 90))
        beam = PositionAndAngle(0, 0, 45)

        result = movement.calculate_interception(beam)
        assert_that(result, is_(position(Position(z, z))))

        movement.offset_position_at_zero(Position(0, z_offset))

        result = movement.calculate_interception(beam)
        assert_that(result, is_(position(Position(z + z_offset,
                                                  z + z_offset))))
    def test_GIVEN_movement_at_30_to_z_beam_intercept_is_at_zero_WHEN_set_position_relative_to_beam_to_10_THEN_position_is_at_10_along_intercept(
            self, add_angle):
        # here the beam intercept is above and to the right of the zero point
        movement = LinearMovementCalc(PositionAndAngle(0, 10, 30 + add_angle))
        beam = PositionAndAngle(0, 0, 0)
        beam_intercept = Position(0, 10)
        dist = 10

        movement.set_distance_relative_to_beam(beam, dist)
        result = movement.position_in_mantid_coordinates()

        assert_that(
            result,
            is_(
                position(
                    Position(beam_intercept.y + dist / 2.0,
                             beam_intercept.z + dist * sqrt(3) / 2.0))))
    def test_GIVEN_movement_45_to_z_at_beam_angle_along_z_WHEN_get_intercept_THEN_position_is_initial_position(
            self, angle):
        y = 0
        z = 10
        movement = LinearMovementCalc(PositionAndAngle(y, z, 45))
        beam = PositionAndAngle(0, 0, angle)

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(y, z))))
    def test_GIVEN_movement_perpendicular_to_z_at_beam_angle_0_WHEN_get_intercept_THEN_position_is_initial_position(
            self):
        y = 0
        z = 10
        movement = LinearMovementCalc(PositionAndAngle(y, z, 90))
        beam = PositionAndAngle(0, 0, 0)

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(y, z))))
示例#7
0
 def _on_long_axis_change(self, displacement):
     """
     Changes the location of the movement strategy when the long axis (the axis along the beam) changes.
     For now assume that the movement is entirely perpendicular to the natural beam.
     Args:
         displacement: the change in the long axis
     """
     offset_position = Position(0, displacement)
     self._movement_strategy.offset_position_at_zero(offset_position)
     self.trigger_listeners(BeamPathUpdate(self))
示例#8
0
    def __init__(self, setup):
        """

        Args:
            setup (ReflectometryServer.geometry.PositionAndAngle):
        """
        self._angle = setup.angle
        self._initial_position_at_zero = Position(setup.y, setup.z)
        self._current_position_at_zero = self._initial_position_at_zero
        self._displacement = 0
    def test_GIVEN_displacement_WHEN_calculating_position_in_mantid_coordinates_THEN_coordinates_at_given_displacement_are_returned(
            self):
        y = 0
        z = 10
        angle = 90
        movement = LinearMovementCalc(PositionAndAngle(y, z, angle))

        displacement = 5
        result = movement.position_in_mantid_coordinates(displacement)

        assert_that(result, is_(position(Position(displacement, z))))
    def test_GIVEN_movement_anti_perpendicular_to_z_at_beam_angle_10_WHEN_get_intercept_THEN_position_is_z_as_initial_y_as_right_angle_triangle(
            self):
        y = 0
        z = 10
        beam_angle = 10
        movement = LinearMovementCalc(PositionAndAngle(y, z, -90))
        beam = PositionAndAngle(0, 0, beam_angle)
        expected_y = z * tan(radians(beam_angle))

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, z))))
    def test_GIVEN_movement_0_to_z_and_beam_angle_45_WHEN_get_intercept_THEN_position_is_on_movement_axis(
            self):
        y = 20
        z = 10
        movement = LinearMovementCalc(PositionAndAngle(y, z, 0))
        beam = PositionAndAngle(0, 0, 45)
        expected_y = y
        expected_z = y

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, expected_z))))
    def test_GIVEN_movement_20_to_z_and_beam_angle_45_WHEN_get_intercept_THEN_position_is_on_movement_axis(
            self):
        beam = PositionAndAngle(0, 0, 45)
        expected_y = 4
        expected_z = 4

        move_angle = 20
        move_z = 2
        move_y = expected_y - (expected_z - move_z) * tan(radians(move_angle))
        movement = LinearMovementCalc(
            PositionAndAngle(move_y, move_z, move_angle))

        result = movement.calculate_interception(beam)

        assert_that(result, is_(position(Position(expected_y, expected_z))))
示例#13
0
    def calculate_interception(self, beam):
        """
        Calculate the interception point of the beam and component
        Args:
            beam (PositionAndAngle) : beam to intercept

        Returns (Position): position of the interception

        """
        assert beam is not None
        y_m = self._current_position_at_zero.y
        z_m = self._current_position_at_zero.z
        angle_m = self._angle
        y_b = beam.y
        z_b = beam.z
        angle_b = beam.angle

        if fabs(angle_b % 180.0 - angle_m % 180.0) <= ANGULAR_TOLERANCE:
            raise ValueError("No interception between beam and movement")
        elif fabs(angle_b % 180.0) <= ANGULAR_TOLERANCE:
            y, z = self._zero_angle(y_b, self._current_position_at_zero,
                                    self._angle)
        elif fabs(angle_m % 180.0) <= ANGULAR_TOLERANCE:
            y, z = self._zero_angle(y_m, beam, beam.angle)
        elif fabs(angle_m % 180.0 -
                  90) <= ANGULAR_TOLERANCE or fabs(angle_m % 180.0 +
                                                   90) <= ANGULAR_TOLERANCE:
            y, z = self._right_angle(z_m, beam, beam.angle)
        elif fabs(angle_b % 180.0 -
                  90) <= ANGULAR_TOLERANCE or fabs(angle_b % 180.0 +
                                                   90) <= ANGULAR_TOLERANCE:
            y, z = self._right_angle(z_b, self._current_position_at_zero,
                                     self._angle)
        else:
            tan_b = tan(radians(angle_b))
            tan_m = tan(radians(angle_m))
            z = 1 / (tan_m - tan_b) * (y_b - y_m + z_m * tan_m - z_b * tan_b)
            y = tan_b * tan_m / (tan_b - tan_m) * (y_m / tan_m - y_b / tan_b +
                                                   z_b - z_m)

        return Position(y, z)