Exemplo n.º 1
0
    def get_torus_polygonmatrix(center_x, center_y, center_z, radius1, radius2,
                                theta_step=30, phi_step=30):
        """
        Generates a PolygonMatrix representing the mesh surface of a torus.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius1: int, the radius of the circle being revolved to make the torus
        radius2: int, the radius of the torus itself
        theta_step: int (optional), the number of steps to use when drawing the
            circle that is revolved to make the torus
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        matrix = PolygonMatrix()
        points = Generator.get_torus_pointmatrix(
            center_x, center_y, center_z, radius1, radius2,
            theta_step=theta_step, phi_step=phi_step)
        for i in range(len(points) - phi_step - 1):
            matrix.add_polygon(points[i],
                               points[i + phi_step + 1],
                               points[i + phi_step])
            matrix.add_polygon(points[i],
                               points[i + 1],
                               points[i + phi_step + 1])
        return matrix
Exemplo n.º 2
0
    def get_sphere_polygonmatrix(center_x, center_y, center_z, radius,
                               theta_step=30, phi_step=30):
        """
        Generates a PolygonMatrix representing the mesh surface of a sphere.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius: int, the radius of the sphere
        theta_step: int (optional), the number of steps to use when drawing the
            circles
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        def x(theta, phi): return radius * cos(theta) + center_x
        def y(theta, phi): return radius * sin(theta) * cos(phi) + center_y
        def z(theta, phi): return radius * sin(theta) * sin(phi) + center_z
        parametric = Parametric(x, y, z)
        matrix = PolygonMatrix()
        points = Generator.get_sphere_pointmatrix(
            center_x, center_y, center_z, radius,
            theta_step=theta_step, phi_step=phi_step)
        for i in range(len(points) - phi_step - 1):
            matrix.add_polygon(points[i],
                               points[i + phi_step + 1],
                               points[i + phi_step])
            matrix.add_polygon(points[i],
                               points[i + 1],
                               points[i + phi_step + 1])
        return matrix
Exemplo n.º 3
0
    def get_torus_polygonmatrix_alt(center_x,
                                    center_y,
                                    center_z,
                                    radius1,
                                    radius2,
                                    theta_step=30,
                                    phi_step=30):
        """
        Alternate version of get_torus_polygonmatrix, based off of DW's code.
        Same for draw, different for fill; More buggy in some ways and less buggy in others.
        Generates a Matrix of points representing the points on the surface of
        a torus.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius1: int, the radius of the circle being revolved to make the torus
        radius2: int, the radius of the torus itself
        theta_step: int (optional), the number of steps to use when drawing the
            circle that is revolved to make the torus
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        matrix = PolygonMatrix()
        points = Generator.get_torus_pointmatrix(center_x,
                                                 center_y,
                                                 center_z,
                                                 radius1,
                                                 radius2,
                                                 theta_step=theta_step,
                                                 phi_step=phi_step)
        temp = []
        for i in range(len(points)):
            temp.append(points[i])
        for i in range(theta_step):
            temp.append(points[i])
        num_points = len(temp)
        num_steps = phi_step
        lat = 0
        lat_stop = num_steps
        longt_stop = num_steps

        while lat < lat_stop:
            longt = 0
            while longt < longt_stop:
                index = lat * num_steps + longt
                p0 = temp[index]
                p1 = temp[(index + num_steps) % num_points]
                p2 = temp[(index + num_steps + 1) % num_points]
                p3 = temp[(index + 1) % num_points]
                matrix.add_polygon(p0, p1, p2)
                matrix.add_polygon(p2, p3, p0)
                longt += 1
            lat += 1
        return matrix
Exemplo n.º 4
0
    def get_torus_polygonmatrix_alt(center_x, center_y, center_z, radius1,
                                    radius2, theta_step=30, phi_step=30):
        """
        Alternate version of get_torus_polygonmatrix, based off of DW's code.
        Same for draw, different for fill; More buggy in some ways and less buggy in others.
        Generates a Matrix of points representing the points on the surface of
        a torus.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius1: int, the radius of the circle being revolved to make the torus
        radius2: int, the radius of the torus itself
        theta_step: int (optional), the number of steps to use when drawing the
            circle that is revolved to make the torus
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        matrix = PolygonMatrix()
        points = Generator.get_torus_pointmatrix(
            center_x, center_y, center_z, radius1, radius2,
            theta_step=theta_step, phi_step=phi_step)
        temp  = []
        for i in range(len(points)):
            temp.append(points[i])
        for i in range(theta_step):
            temp.append(points[i])
        num_points = len(temp)
        num_steps = phi_step
        lat = 0
        lat_stop = num_steps
        longt_stop = num_steps

        while lat < lat_stop:
            longt = 0
            while longt < longt_stop:
                index = lat * num_steps + longt
                p0 = temp[ index ]
                p1 = temp[ (index + num_steps) % num_points ]
                p2 = temp[ (index + num_steps + 1) % num_points ]
                p3 = temp[ (index + 1) % num_points ]
                matrix.add_polygon(p0, p1, p2)
                matrix.add_polygon(p2, p3, p0)
                longt+= 1
            lat+= 1
        return matrix
Exemplo n.º 5
0
    def get_box_polygonmatrix(x, y, z, width, height, depth):
        """
        Generates a PolygonMatrix representing the mesh surface of a box.

        Parameters:
        x: int, the x coordinate of the front left bottom of the box
        y: int, the y coordinate of the front left bottom of the box
        z: int, the z coordinate of the front left bottom of the box
        width: int, the width of the box
        height: int, the height of the box
        depth: int, the depth of the box
        """
        pointmatrix = Generator.get_box_pointmatrix(x, y, z, width, height,
                                                    depth)
        return PolygonMatrix(matrix=[
            # Front
            pointmatrix[3],
            pointmatrix[1],
            pointmatrix[0],
            pointmatrix[3],
            pointmatrix[2],
            pointmatrix[1],
            # Right
            pointmatrix[2],
            pointmatrix[5],
            pointmatrix[1],
            pointmatrix[2],
            pointmatrix[6],
            pointmatrix[5],
            # Back
            pointmatrix[6],
            pointmatrix[4],
            pointmatrix[5],
            pointmatrix[6],
            pointmatrix[7],
            pointmatrix[4],
            # Left
            pointmatrix[7],
            pointmatrix[0],
            pointmatrix[4],
            pointmatrix[7],
            pointmatrix[3],
            pointmatrix[0],
            # Top
            pointmatrix[7],
            pointmatrix[2],
            pointmatrix[3],
            pointmatrix[7],
            pointmatrix[6],
            pointmatrix[2],
            # Bottom
            pointmatrix[0],
            pointmatrix[5],
            pointmatrix[4],
            pointmatrix[0],
            pointmatrix[1],
            pointmatrix[5]
        ])
Exemplo n.º 6
0
    def get_torus_polygonmatrix(center_x,
                                center_y,
                                center_z,
                                radius1,
                                radius2,
                                theta_step=30,
                                phi_step=30):
        """
        Generates a PolygonMatrix representing the mesh surface of a torus.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius1: int, the radius of the circle being revolved to make the torus
        radius2: int, the radius of the torus itself
        theta_step: int (optional), the number of steps to use when drawing the
            circle that is revolved to make the torus
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        matrix = PolygonMatrix()
        points = Generator.get_torus_pointmatrix(center_x,
                                                 center_y,
                                                 center_z,
                                                 radius1,
                                                 radius2,
                                                 theta_step=theta_step,
                                                 phi_step=phi_step)
        for i in range(len(points) - phi_step - 1):
            matrix.add_polygon(points[i], points[i + phi_step + 1],
                               points[i + phi_step])
            matrix.add_polygon(points[i], points[i + 1],
                               points[i + phi_step + 1])
        return matrix
Exemplo n.º 7
0
    def get_sphere_polygonmatrix(center_x,
                                 center_y,
                                 center_z,
                                 radius,
                                 theta_step=30,
                                 phi_step=30):
        """
        Generates a PolygonMatrix representing the mesh surface of a sphere.

        Parameters:
        center_x: int, the x coordinate of the center of the sphere
        center_y: int, the y coordinate of the center of the sphere
        center_z: int, the z coordinate of the center of the sphere
        radius: int, the radius of the sphere
        theta_step: int (optional), the number of steps to use when drawing the
            circles
        phi_step: int(optional), the number of steps to use when rotating the
            circles about the center point
        """
        def x(theta, phi):
            return radius * cos(theta) + center_x

        def y(theta, phi):
            return radius * sin(theta) * cos(phi) + center_y

        def z(theta, phi):
            return radius * sin(theta) * sin(phi) + center_z

        parametric = Parametric(x, y, z)
        matrix = PolygonMatrix()
        points = Generator.get_sphere_pointmatrix(center_x,
                                                  center_y,
                                                  center_z,
                                                  radius,
                                                  theta_step=theta_step,
                                                  phi_step=phi_step)
        for i in range(len(points) - phi_step - 1):
            matrix.add_polygon(points[i], points[i + phi_step + 1],
                               points[i + phi_step])
            matrix.add_polygon(points[i], points[i + 1],
                               points[i + phi_step + 1])
        return matrix