Example #1
0
 def __init__(self, F: fn.Function, G: fn.Function):
     assert F.get_vars() - {'x', 'y', 'z'} == set()
     assert G.get_vars() - {'x', 'y', 'z'} == set()
     self._F = F
     self._G = G
     self._vars = self._F.get_vars()
     self.x = fn.Var('x')
     self.y = fn.Var('y')
     self.z = fn.Var('z')
Example #2
0
 def osculating_plane(self):
     """ (R - r(t0), r'(t0), r''(t0)) = 0
     R = (X, Y, Z)
     """
     r = self.vector
     X = fn.Var('X')
     Y = fn.Var('Y')
     Z = fn.Var('Z')
     dr1 = r.derivative()
     dr2 = dr1.derivative()
     tmp = dr1.cross(dr2)
Example #3
0
    def __init__(self,
                 x: fn.Function,
                 y: fn.Function,
                 z: fn.Function,
                 t_1: float,
                 t_2: float,
                 str_repr=''):
        assert x.get_vars() - {
            't',
        } == set()
        assert y.get_vars() - {
            't',
        } == set()
        assert z.get_vars() - {
            't',
        } == set()

        self._t = fn.Var('t')
        self._t.right = min(self._t.right, t_2)
        self._t.left = max(self._t.left, t_1)
        self.x = x
        self.y = y
        self.z = z
        self._str_repr = str_repr or f'{x}, {y}, {z}'
        self.left = self._t.left
        self.right = self._t.right
Example #4
0
    def _precompute_implicit(self, p0, eps=10e-6):
        x0, y0, z0 = p0
        self._vals = {self.x: x0, self.y: y0, self.z: z0}
        for var in self._vars:
            if abs(self._get_jacobi(var)(x=x0, y=y0, z=z0)) > eps:
                break
        else:
            raise ImplicitFuncTheoremError(p0)
        self._z = var
        self._x, self._y = self._vars - {
            self._z,
        }  # type: fn.Var
        self._x_found = {self._vals[self._z]: self._vals[self._x]}
        self._y_found = {self._vals[self._z]: self._vals[self._y]}
        self._t = fn.Var('t')
        self._t0 = self._vals[self._z]
        self._t.set_value(self._t0)

        def _x_func(t):
            if t in self._x_found:
                return self._x_found[t]
            else:
                raise NotFoundError()

        def _y_func(t):
            if t in self._y_found:
                return self._y_found[t]
            else:
                raise NotFoundError()

        self._x_func = fn.from_func_factory(_x_func, {self._t})
        self._y_func = fn.from_func_factory(_y_func, {self._t})
        self._z_func = fn.from_var_factory(self._t)
        self._kwargs1 = {
            self._x.name: fn.from_const_factory(self._vals[self._x]),
            self._y.name: fn.from_const_factory(self._vals[self._y]),
            self._z.name: fn.from_const_factory(self._vals[self._z])
        }
        self._kwargs2 = {
            self._x.name: self._x_func,
            self._y.name: self._y_func,
            self._z.name: self._z_func
        }

        self._dFdx = self._F.partial_derivative(self._x)
        self._dFdy = self._F.partial_derivative(self._y)
        self._dFdz = self._F.partial_derivative(self._z)

        self._dGdx = self._G.partial_derivative(self._x)
        self._dGdy = self._G.partial_derivative(self._y)
        self._dGdz = self._G.partial_derivative(self._z)

        a11, a12 = self._dFdx.substitute(**self._kwargs1)(), \
                   self._dFdy.substitute(**self._kwargs1)()
        a21, a22 = self._dGdx.substitute(**self._kwargs1)(), \
                   self._dGdy.substitute(**self._kwargs1)()
        self._A = np.array([[a11, a12], [a21, a22]])
Example #5
0
    def __init__(self,
                 x: fn.Function,
                 y: fn.Function,
                 z: fn.Function,
                 u1=None,
                 u2=None,
                 v1=None,
                 v2=None):
        assert x.get_vars() == {'u', 'v'}
        assert y.get_vars() == {'u', 'v'}
        assert z.get_vars() == {'u', 'v'}
        self.x = x
        self.y = y
        self.z = z
        self._u = fn.Var('u')
        self._v = fn.Var('v')

        self._u.right = min(self._u.right, u2)
        self._u.left = max(self._u.left, u1)
        self._v.right = min(self._v.right, v2)
        self._v.left = max(self._v.left, v1)
Example #6
0
    def _add_found(dvdz: float, _v_found: dict, v0: float):
        dvdz = dvdz * fn.Function.delta_x * 2
        v1 = dvdz
        v2 = 0
        _v_found[v0 + fn.Function.delta_x] = v1
        _v_found[v0 - fn.Function.delta_x] = v2

    @staticmethod
    def _add_found2(d2vdz2: float, _v_found: dict, v0: float):
        delta_x = fn.Function.delta_x
        _v_found[v0 + 2 * delta_x] = _v_found[v0 - 2 * delta_x] \
                = 2 * delta_x ** 2 * d2vdz2 + _v_found[v0]


if __name__ == "__main__":
    x_func = fn.from_var_factory(fn.Var('x'))
    y_func = fn.from_var_factory(fn.Var('y'))
    z_func = fn.from_var_factory(fn.Var('z'))

    test_F = x_func + fn.sinh(x_func) - fn.sin(y_func) - y_func + z_func * 0
    test_G = z_func + fn.exp(z_func) - x_func - fn.log(1 +
                                                       x_func) - 1 + y_func * 0

    p = (0, 0, 0)

    test = ImplicitCurve3D(test_F, test_G)
    res = test.implicit_theorem(p)

    curve = ParamCurve3D(res)

    print(res(1))
Example #7
0
    def plot(self, dots=1000, start=-100, end=100):
        self.reset_axes()
        start = max(start, self.vector.left)
        end = min(end, self.vector.right)
        t = np.linspace(start, end, dots)
        x, y, z = self(t)
        self.ax.plot(x, y, z, c='r')

    def frenet(self, t0):
        tau = self.tangent_unit()(t=t0)
        beta = self.binormal_unit()(t=t0)
        nu = self.normal_unit()(t=t0)

        point = self(t=t0)
        x0, y0, z0 = point
        X = [x0, x0, x0]
        Y = [y0, y0, y0]
        Z = [z0, z0, z0]
        return self.ax.quiver(X, Y, Z, tau, beta, nu)


if __name__ == '__main__':

    t = fn.Var('t')
    r = VectorFunc(1 + fn.cos(t), fn.sin(t),
                   2 * fn.sin(fn.from_var_factory(t) / 2), 0, 4 * np.pi)
    curve = ParamCurve3D(r)
    curve.plot()
    curve.frenet(2)
    plt.show()