Пример #1
0
def rod_setup(dim1: Tuple[float], dim2: Tuple[float]) -> Faces:  # validated
    """defines points in a circle with triangle based end caps"""
    # 4,8,12,16,... becomes 5,9,13,17,...
    ntheta = 17
    thetas = np.radians(np.linspace(0., 360., ntheta))

    nfaces = 0
    all_faces = []
    points_list = []
    x = np.zeros(ntheta)
    for dim in (dim1, dim2):
        radius, = dim
        y = radius * np.cos(thetas)
        z = radius * np.sin(thetas)
        xyz = np.vstack([x, y, z]).T
        assert xyz.shape == (ntheta, 3), xyz.shape

        # the tri_cap buils triangles that fan out from the first node
        tris = tri_cap(ntheta)

        # we need to use the tolist because we're going to
        # combine quads and tris (the elements have different
        # lengths)
        all_faces += (nfaces + tris).tolist()
        nfaces += tris.shape[0]
        points_list.append(xyz)

    # the main cylinder uses the points defined independent
    # of the points n1/n2
    faces = elements_from_quad(2, ntheta)
    all_faces += faces.tolist()
    return all_faces, points_list[0], points_list[1]
Пример #2
0
def tube_faces(n1: int, n2: int, xform, dim1: Tuple[float, float],
               dim2: Tuple[float, float]):  # validated
    """
    defines a rod with a hole
    """
    # 4,8,12,16,... becomes 5,9,13,17,...
    thetas = np.radians(np.linspace(0., 360., 17))
    ntheta = len(thetas)
    npoints = ntheta * 2

    points_list1 = []
    points_list2 = []
    x = np.zeros(ntheta)

    for nid, dim in [(n1, dim1), (n2, dim2)]:
        radius_out, radius_in = dim

        # outer rod
        y = radius_out * np.cos(thetas)
        z = radius_out * np.sin(thetas)
        xyz1 = np.vstack([x, y, z]).T
        points1i = xyz1 @ xform + nid
        points_list2.append(points1i)

        # inner rod
        y = radius_in * np.cos(thetas)
        z = radius_in * np.sin(thetas)
        xyz2 = np.vstack([x, y, z]).T
        points2i = xyz2 @ xform + nid
        points_list1.append(points2i)

    # the main cylinder uses the points defined independent
    # of the inner/outer faces
    faces_n1 = elements_from_quad(2, ntheta)
    faces_n2 = faces_n1 + npoints

    #faces_n1
    #[[ 0 17 18  1]
    #[ 1 18 19  2]
    #[ 2 19 20  3]
    #[ 3 20 21  4]
    #[ 4 21 22  5]
    #[ 5 22 23  6]

    # we use slicing to link the outer surface to the
    # inner surface using quads
    #
    # we'd like to hstack the column arrays, but hstack and a
    # transpose is easier.  Presumably, a "newaxis" index would work...
    faces_out = np.vstack(
        [faces_n1[:, 0], faces_n1[:, 3], faces_n2[:, 3], faces_n2[:, 0]]).T
    faces_in = np.vstack(
        [faces_n1[:, 1], faces_n1[:, 2], faces_n2[:, 2], faces_n2[:, 1]]).T

    # combine everything together
    all_faces = np.vstack([faces_n1, faces_n2, faces_out, faces_in])
    points = np.vstack(points_list1 + points_list2)
    return all_faces, points, points.shape[0]
Пример #3
0
def tube_setup(
    dim1: Tuple[float, float], dim2: Tuple[float, float]
) -> Tuple[Faces, NDArrayN3float, NDArrayN3float]:  # validated
    """defines a rod with a hole"""
    # 4,8,12,16,... becomes 5,9,13,17,...
    ntheta = 17
    thetas = np.radians(np.linspace(0., 360., ntheta))
    npoints = ntheta * 2

    x = np.zeros(ntheta)

    points = []
    #points_list_in = []
    #points_list_out = []
    for dim in (dim1, dim2):
        radius_out, radius_in = dim

        # inner rod
        y = radius_in * np.cos(thetas)
        z = radius_in * np.sin(thetas)
        xyz2 = np.vstack([x, y, z]).T
        #points_list_in.append(xyz2)

        # outer rod
        y = radius_out * np.cos(thetas)
        z = radius_out * np.sin(thetas)
        xyz1 = np.vstack([x, y, z]).T
        #points_list_out.append(xyz1)
        xyz = np.vstack([xyz1, xyz2])
        points.append(xyz)

    # the main cylinder uses the points defined independent
    # of the inner/outer faces
    faces_n1 = elements_from_quad(2, ntheta)
    faces_n2 = faces_n1 + npoints

    #faces_n1
    #[[ 0 17 18  1]
    #[ 1 18 19  2]
    #[ 2 19 20  3]
    #[ 3 20 21  4]
    #[ 4 21 22  5]
    #[ 5 22 23  6]

    # we use slicing to link the outer surface to the
    # inner surface using quads
    #
    # we'd like to hstack the column arrays, but hstack and a
    # transpose is easier.  Presumably, a "newaxis" index would work...
    faces_out = np.vstack(
        [faces_n1[:, 0], faces_n1[:, 3], faces_n2[:, 3], faces_n2[:, 0]]).T
    faces_in = np.vstack(
        [faces_n1[:, 1], faces_n1[:, 2], faces_n2[:, 2], faces_n2[:, 1]]).T

    # combine everything together
    all_faces = np.vstack([faces_n1, faces_n2, faces_out, faces_in])
    return all_faces, points[0], points[1]
Пример #4
0
def rod_faces(n1: int, n2: int, xform, dim1: Tuple[float, float],
              dim2: Tuple[float, float]):  # validated
    """
    defines points in a circle with triangle based end caps
    """
    # 4,8,12,16,... becomes 5,9,13,17,...
    thetas = np.radians(np.linspace(0., 360., 17))
    ntheta = len(thetas)

    nfaces = 0
    all_faces = []
    points_list = []
    x = np.zeros(ntheta)
    for nid, dim in [(n1, dim1), (n2, dim2)]:
        radius, = dim
        y = radius * np.cos(thetas)
        z = radius * np.sin(thetas)
        xyz = np.vstack([x, y, z]).T
        assert xyz.shape == (ntheta, 3), xyz.shape

        pointsi = xyz @ xform + nid
        points_list.append(pointsi)

        # the tri_cap is made from points that aren't defined yet
        # (the n1/n2 end points)
        tris = tri_cap(ntheta)

        # we need to use the tolist because we're going to
        # combine quads and tris (the elements have different
        # lengths)
        all_faces += (nfaces + tris).tolist()
        nfaces += tris.shape[0]

    # the main cylinder uses the points defined independent
    # of the points n1/n2
    faces = elements_from_quad(2, ntheta)
    all_faces += faces.tolist()

    # used by the tri_caps
    points_list.append(n1)
    points_list.append(n2)
    points = np.vstack(points_list)
    return all_faces, points, points.shape[0]