Beispiel #1
0
    def __new__(cls,
                r1,
                r2,
                *args,
                npts=100,
                center=None,
                flat=False,
                basis=None,
                **kwargs):
        if center is None:
            center = _arrays.Vector(0, 0, 0)
        else:
            center = _arrays.Vector(center)

        theta = _np.linspace(-_np.pi, _np.pi, npts)
        x = r1 * _np.cos(theta)
        y = r2 * _np.sin(theta)

        if flat:
            return super().__new__(cls, x + center[0], y + center[0], *args,
                                   **kwargs)
        else:
            z = _np.zeros_like(x)
            if basis is None:
                return super().__new__(cls, x + center[0], y + center[1],
                                       z + center[2], *args, **kwargs)
            out = super().__new__(cls, x, y, z, *args,
                                  **kwargs).change_reference_frame(basis)
            out += center.column
            return out
Beispiel #2
0
    def from_two_points_and_normal(cls, p1, p2, normal, **kwargs):

        p1 = _arrays.Vector(p1).make_3d().squeeze()
        p2 = _arrays.Vector(p2).make_3d().squeeze()

        kk = _arrays.Vector(normal).hat.squeeze()
        jj = _arrays.Vector(p1.perpendicular(kk)).hat.squeeze()
        ii = _arrays.Vector(_np.cross(_np.array(jj), _np.array(kk))).hat

        basis = _arrays.Basis(ii, jj, kk)

        r = (p2 - p1).magnitude() / 2

        return cls(r, center=(p1 + p2) / 2, basis=basis, **kwargs)
Beispiel #3
0
 def get_normal(self):
     k_test = math.approximate_normal(self-self.centroid)
     i = math.normalize(self[:, 0, None] - self.centroid)
     n = math.normalize(
         self[:, self.shape[-1]//4, None] - self.centroid)
     k_test = math.normalize(
         math.cross(i, n))
     j_test = math.cross(k_test, i)
     alpha1 = math.smallest_angle_between_vectors(j_test, n)
     alpha2 = math.smallest_angle_between_vectors(-j_test, n)
     if alpha1 < alpha2:
         return arrays.Vector(math.normalize(k_test))
     else:
         return arrays.Vector(math.normalize(-k_test))
Beispiel #4
0
    def __new__(cls, s1, s2, s3, s4, basis=None, corner=None, **kwargs):

        out = _np.concatenate([s1, s2[:, 1:], s3[:, 1:], s4[:, 1:-1]], axis=1)

        if basis is not None:
            shift = _arrays.Vector(_math.contour_centroid(out)).column
            out -= shift
            out = _math.scalar_project(out, basis)
            out += shift

        if corner is not None:
            corner = _arrays.Vector(*corner).make_3d().make_column()
            out += corner

        return super().__new__(cls, out, **kwargs)
Beispiel #5
0
                 c3=0.75):
        self.s1 = contour(_np.linspace(0, c1, npts))
        self.s2 = contour(_np.linspace(c1, c2, npts))
        self.s3 = contour(_np.linspace(c2, c3, npts))
        self.s4 = contour(_np.linspace(c3, 1, npts))
        self.sections = [self.s1, self.s2, self.s3, self.s4]
        self.maxiter = 4


if __name__ == "__main__":

    import pymethods.pyplot as plt
    import pymethods.math as pmath
    import pymethods.arrays as pma

    basis = pma.Basis(pma.Vector(1, 0, 0).rotation_matrix(45, units="d"))

    ellipse = Ellipse(1, 1, basis=basis, center=[1, 1, 1])

    square = Square(1, 100, basis=basis)

    s1, s2, s3, s4 = square.transfinitable_corner_split()

    plt.plot_stream3d(s1, color="green")
    plt.plot_stream3d(s2, color="green")
    plt.plot_stream3d(s3, color="green")
    plt.plot_stream3d(s4, color="green")

    square.scatter3d_corners(color_coded=True)

    basis.quiver3d()
Beispiel #6
0
 def initialize_class(self, s, **kwargs):
     if len(s.shape) == 0:
         return arrays.Vector(np.stack([f(s) for f in self.dim_funcs]), **kwargs)
     else:
         return self.__class__(np.stack([f(s) for f in self.dim_funcs]), **kwargs)