def max_distance(curve1: "Curve", curve2: "Curve", t_range1=(0, 1), t_range2=(0, 1), samples=9):

        """
        Return the approximate maximum distance between two Curves for different values of t.

        WARNING: should only be used when comparing relatively flat curve segments. If one of the two
        curves has very eccentric humps, the tip of the hump may not be sampled.

        :param curve1: the first of two curves to be compared.
        :param curve2: the second of two curves to be compared.
        :param t_range1: (min_t, max_t) the range of t values which should be sampled in the first curve. The default
        value of (0, 1) samples the whole curve. A value of (0, 5) would only sample from the first half of the curve.
        :param t_range2: (min_t, max_t) the range of t values which should be sampled in the second curve. The default
        value of (0, 1) samples the whole curve. A value of (0, 5) would only sample from the first half of the curve.
        :param samples: the number of samples which should be taken. Higher values are slower but more accurate.
        :return: the approximate maximum distance
        """

        maximum_distance = 0
        for i in range(samples):
            t = (i + 1) / (samples + 1)
            t1 = formulas.linear_map(t_range1[0], t_range1[1], t)
            t2 = formulas.linear_map(t_range2[0], t_range2[1], t)

            distance = abs(curve1.point(t1) - curve2.point(t2))
            maximum_distance = distance if distance > maximum_distance else maximum_distance

        return maximum_distance
Exemple #2
0
 def derivative(self, t):
     angle = formulas.linear_map(self.start_angle, self.end_angle, t)
     return self.angle_to_derivative(angle)
Exemple #3
0
 def point(self, t):
     angle = formulas.linear_map(self.start_angle, self.end_angle, t)
     return self.angle_to_point(angle)