Esempio n. 1
0
    def impulse00_y(self, i):
        eps = 1e-8

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return cpsi_1d(self.X(t)) * dF_dp(i, t)
            else:  # < 0
                return -cpsi_1d(self.X(t)) * dF_dp(i, t)

        result = 0
        a, b, c, d = cubicCoefficients(self.yPara)

        # t0
        roots = cubic(a, b, c, d)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root)

        # t1
        roots = cubic(a, b, c, d - 1.0)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root)

        return result
Esempio n. 2
0
    def impulse11_y(self, i, j, kx, ky):
        eps = 1e-8

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return cpsi_1d_jk(self.X(t), j, kx) * dF_dp(i, t)
            else:  # < 0
                return -cpsi_1d_jk(self.X(t), j, kx) * dF_dp(i, t)

        result = 0
        a, b, c, d = cubicCoefficients(self.yPara)

        # t0
        roots = cubic(a, b, c, d - float(ky) / 2**j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root) * 2**j

        # t1
        roots = cubic(a, b, c, d - (0.5 + ky) / 2**j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root) * 2**(j + 1)

        # t2
        roots = cubic(a, b, c, d - (1.0 + ky) / 2**j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root) * 2**j

        return result
Esempio n. 3
0
    def impulse11_y(self, i, j, kx, ky):
        eps = 1e-8

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return cpsi_1d_jk(self.X(t), j, kx) * dF_dp(i, t)
            else:  # < 0
                return -cpsi_1d_jk(self.X(t), j, kx) * dF_dp(i, t)

        result = 0
        a, b, c, d = cubicCoefficients(self.yPara)

        # t0
        roots = cubic(a, b, c, d - float(ky) / 2 ** j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root) * 2 ** j

        # t1
        roots = cubic(a, b, c, d - (0.5 + ky) / 2 ** j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root) * 2 ** (j + 1)

        # t2
        roots = cubic(a, b, c, d - (1.0 + ky) / 2 ** j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root) * 2 ** j

        return result
Esempio n. 4
0
    def impulse00_y(self, i):
        eps = 1e-8

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return cpsi_1d(self.X(t)) * dF_dp(i, t)
            else:  # < 0
                return -cpsi_1d(self.X(t)) * dF_dp(i, t)

        result = 0
        a, b, c, d = cubicCoefficients(self.yPara)

        # t0
        roots = cubic(a, b, c, d)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root)

        # t1
        roots = cubic(a, b, c, d - 1.0)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root)

        return result
Esempio n. 5
0
    def impulse10_y(self, i, j, k):
        eps = 1e-8
        kx, ky = k

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return CubicBezier.cpsi_1d_jk(self.X(t), j, kx) * CubicBezier.dF_dp(i, t)
            else:  # < 0
                return -CubicBezier.cpsi_1d_jk(self.X(t), j, kx) * CubicBezier.dF_dp(i, t)

        result = 0
        a, b, c, d = CubicBezier.cubicCoefficients(self.y0, self.y1, self.y2, self.y3)

        # t0
        roots = cubic(a, b, c, d - float(ky) / 2 ** j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root) * 2 ** j

        # t1
        roots = cubic(a, b, c, d - (1.0 + ky) / 2 ** j)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root) * 2 ** j

        return result
Esempio n. 6
0
    def clip(self, left, right, bottom, top, return_t = False):
        def is_t_in(t, eps = 1e-5):
            pt = self.evaluate(t)
            return left-eps<=pt[0]<=right+eps and top-eps<=pt[1]<=bottom+eps
        def is_subsection_valid(sec, eps = 1e-5):
            return  abs(sec.x0 - right) < eps and abs(sec.x1 - right) < eps \
                and abs(sec.x2 - right) < eps and abs(sec.x3 - right) < eps \
                 or abs(sec.y0 -bottom) < eps and abs(sec.y1 -bottom) < eps \
                and abs(sec.y2 -bottom) < eps and abs(sec.y3 -bottom) < eps

        ax = -self.x0 + 3*self.x1 - 3*self.x2 + self.x3
        bx = 3*self.x0 - 6*self.x1 + 3*self.x2
        cx, _dx = 3*self.x1 - 3*self.x0, self.x0
        ay = -self.y0 + 3*self.y1 - 3*self.y2 + self.y3
        by = 3*self.y0 - 6*self.y1 + 3*self.y2
        cy, _dy = 3*self.y1 - 3*self.y0, self.y0
        ts = [0]
        ts += cubic(ax, bx, cx, _dx-left)
        ts += cubic(ax, bx, cx, _dx-right)
        ts += cubic(ay, by, cy, _dy-bottom)
        ts += cubic(ay, by, cy, _dy-top)
        ts.append(1)
        ts = [t for t in ts if 0 <= t <= 1 and is_t_in(t)]
        ts = sorted(ts)
        ts = [t for i, t in enumerate(ts) if t != ts[i-1]]
        pairs = [(ts[i-1], t) for i, t in enumerate(ts) \
                    if i > 0 and is_t_in((t + ts[i-1]) * 0.5)]
        sections = []
        for a, b in pairs:
            sec = self.subsection(a, b)
            if not is_subsection_valid(sec):
                sections.append((a, b) if return_t else sec)
        return sections
Esempio n. 7
0
    def impulse00_y(self, i):
        eps = 1e-8

        def helper(t):
            if self.Yp(t) >= -eps:  # >= 0
                return CubicBezier.cphi_1d(self.X(t)) * CubicBezier.dF_dp(i, t)
            else:  # < 0
                return -CubicBezier.cphi_1d(self.X(t)) * CubicBezier.dF_dp(i, t)

        result = 0
        a, b, c, d = CubicBezier.cubicCoefficients(self.y0, self.y1, self.y2, self.y3)

        # t0
        roots = cubic(a, b, c, d)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result += helper(root)

        # t1
        roots = cubic(a, b, c, d - 1.0)
        for root in roots:
            if -eps <= root <= 1 + eps:
                result -= helper(root)

        return result
Esempio n. 8
0
    def clip(self, left, right, bottom, top):
        def is_t_in(t, eps=1e-5):
            pt = self.evaluate(t)
            return left - eps <= pt[0] <= right + eps and top - eps <= pt[
                1] <= bottom + eps

        ax = -self.x0 + 3 * self.x1 - 3 * self.x2 + self.x3
        bx = 3 * self.x0 - 6 * self.x1 + 3 * self.x2
        cx, _dx = 3 * self.x1 - 3 * self.x0, self.x0
        ay = -self.y0 + 3 * self.y1 - 3 * self.y2 + self.y3
        by = 3 * self.y0 - 6 * self.y1 + 3 * self.y2
        cy, _dy = 3 * self.y1 - 3 * self.y0, self.y0
        ts = [0]
        ts += cubic(ax, bx, cx, _dx - left)
        ts += cubic(ax, bx, cx, _dx - right)
        ts += cubic(ay, by, cy, _dy - bottom)
        ts += cubic(ay, by, cy, _dy - top)
        ts.append(1)
        ts = [t for t in ts if 0 <= t <= 1 and is_t_in(t)]
        ts = sorted(ts)
        ts = [t for i, t in enumerate(ts) if t != ts[i - 1]]
        pairs = [(ts[i-1], t) for i, t in enumerate(ts) \
                    if i > 0 and is_t_in((t + ts[i-1]) * 0.5)]
        sections = [self.subsection(a, b) for a, b in pairs]
        return sections
    def clip(self, left, right, bottom, top):
        def is_t_in(t, eps = 1e-5):
            pt = self.evaluate(t)
            return left-eps<=pt[0]<=right+eps and top-eps<=pt[1]<=bottom+eps

        ax = -self.x0 + 3*self.x1 - 3*self.x2 + self.x3
        bx = 3*self.x0 - 6*self.x1 + 3*self.x2
        cx, _dx = 3*self.x1 - 3*self.x0, self.x0
        ay = -self.y0 + 3*self.y1 - 3*self.y2 + self.y3
        by = 3*self.y0 - 6*self.y1 + 3*self.y2
        cy, _dy = 3*self.y1 - 3*self.y0, self.y0
        ts = [0]
        ts += cubic(ax, bx, cx, _dx-left)
        ts += cubic(ax, bx, cx, _dx-right)
        ts += cubic(ay, by, cy, _dy-bottom)
        ts += cubic(ay, by, cy, _dy-top)
        ts.append(1)
        ts = [t for t in ts if 0 <= t <= 1 and is_t_in(t)]
        ts = sorted(ts)
        ts = [t for i, t in enumerate(ts) if t != ts[i-1]]
        pairs = [(ts[i-1], t) for i, t in enumerate(ts) \
                    if i > 0 and is_t_in((t + ts[i-1]) * 0.5)]
        sections = [self.subsection(a, b) for a, b in pairs]
        return sections