def angle_between(self, point):
        """

        :param point:
        :return:
        """

        my_length = self.length
        pos_length = point.length
        numerator = self.x*point.x + self.y*point.y
        denominator = my_length * pos_length

        if value.equivalent(denominator.value, 0.0, 1e-6):
            return angle.Angle(radians=0.0, uncertainty=0.5*math.pi)

        result = numerator/denominator

        if value.equivalent(result.value, 1.0, 1e-5):
            return angle.Angle()

        try:
            if value.equivalent(result.value, -1.0, 1e-5):
                a = math.pi
            else:
                a = math.acos(result.raw)
        except Exception:
            print('[ERROR]: Unable to calculate angle between', result)
            return angle.Angle()

        if value.equivalent(a, math.pi, 1e-5):
            return angle.Angle(radians=a, uncertainty_degrees=180.0)

        try:
            aUnc = abs(1.0 / (1.0 - result.raw * result.raw) ** 0.5) * \
                   result.raw_uncertainty
        except Exception as err:
            print('[ERROR]: Unable to calculate angle between uncertainty',
                  result, a)
            return angle.Angle()

        return angle.Angle(radians=a, uncertainty=aUnc)
    def angle_between(self, point):
        """

        :param point:
        :return:
        """

        my_length = self.length
        pos_length = point.length
        numerator = self.x * point.x + self.y * point.y
        denominator = my_length * pos_length

        if value.equivalent(denominator.value, 0.0, 1e-6):
            return angle.Angle(radians=0.0, uncertainty=0.5 * math.pi)

        result = numerator / denominator

        if value.equivalent(result.value, 1.0, 1e-5):
            return angle.Angle()

        try:
            if value.equivalent(result.value, -1.0, 1e-5):
                a = math.pi
            else:
                a = math.acos(result.raw)
        except Exception:
            print("[ERROR]: Unable to calculate angle between", result)
            return angle.Angle()

        if value.equivalent(a, math.pi, 1e-5):
            return angle.Angle(radians=a, uncertainty_degrees=180.0)

        try:
            aUnc = abs(1.0 / (1.0 - result.raw * result.raw) ** 0.5) * result.raw_uncertainty
        except Exception as err:
            print("[ERROR]: Unable to calculate angle between uncertainty", result, a)
            return angle.Angle()

        return angle.Angle(radians=a, uncertainty=aUnc)
Beispiel #3
0
 def test_equivalent(self):
     """test_equivalent doc..."""
     self.assertTrue(value.equivalent(1.0, 1.001, 0.01))
     self.assertFalse(value.equivalent(1.0, 1.011, 0.01))
 def test_equivalent(self):
     """test_equivalent doc..."""
     self.assertTrue(value.equivalent(1.0, 1.001, 0.01))
     self.assertFalse(value.equivalent(1.0, 1.011, 0.01))