def get_polygon_edgematrix(center_x, center_y, radius, sides): """ Generates an EdgeMatrix of lines representing a regular polygon centered at the given points inscribed within a circle of the given radius. Parameters: center_x: int, the x coordinate of the center of the polygon center_y: int, the y coordinate of the center of the polygon radius: int, the radius of the circle sides: int, the number of sides in the polygon """ def x(t): return cos(t) * radius + center_x def y(t): return sin(t) * radius + center_y def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 2 * pi, sides) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_hermite_curve_edgematrix(p1, r1, p2, r2, step=30): """ Generates an EdgeMatrix of lines representing a hermite curve. Parameters: p1: list, the first point of the hermite curve r1: list, the rate of change at p1 p2: list, the second point of the hermite curve r2: list, the rate of change at p2 step: int (optional), the number of steps to use when drawing splines for the hermite curve """ points = Matrix(matrix=[p1, p2, r1, r2]) inverse = Matrix([[2, -2, 1, 1], [-3, 3, -2, -1], [0, 0, 1, 0], [1, 0, 0, 0]]) c = inverse * points def x(t): return Generator.get_hermite_function(c[0][0], c[1][0], c[2][0], c[3][0])(t) def y(t): return Generator.get_hermite_function(c[0][1], c[1][1], c[2][1], c[3][1])(t) def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 1, step) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_bezier_curve_edgematrix(p1, i1, i2, p2, step=30): """ Generates an EdgeMatrix of lines representing a bezier curve. Parameters: p1: list, the first endpoint of the bezier curve i1: list, the first influence point of the bezier curve i2: list, the second influence point of the bezier curve p2: list, the second endpoint of the bezier curve step: int (optional), the number of steps to use when drawing splines for the hermite curve """ def x(t): return Generator.get_bezier_function(p1[0], i1[0], i2[0], p2[0])(t) def y(t): return Generator.get_bezier_function(p1[1], i1[1], i2[1], p2[1])(t) def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 1, step) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_hermite_curve_edgematrix(p1, r1, p2, r2, step=30): """ Generates an EdgeMatrix of lines representing a hermite curve. Parameters: p1: list, the first point of the hermite curve r1: list, the rate of change at p1 p2: list, the second point of the hermite curve r2: list, the rate of change at p2 step: int (optional), the number of steps to use when drawing splines for the hermite curve """ points = Matrix(matrix=[p1, p2, r1, r2]) inverse = Matrix([ [2, -2, 1, 1], [-3, 3, -2, -1], [0, 0, 1, 0], [1, 0, 0, 0]]) c = inverse * points def x(t): return Generator.get_hermite_function( c[0][0], c[1][0], c[2][0], c[3][0])(t) def y(t): return Generator.get_hermite_function( c[0][1], c[1][1], c[2][1], c[3][1])(t) def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 1, step) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_torus_pointmatrix(center_x, center_y, center_z, radius1, radius2, theta_step=30, phi_step=30): """ 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 """ def x(theta, phi): return radius1 * cos(theta) + center_x def y(theta, phi): return cos(phi) * ( radius1 * sin(theta) + radius2) + center_y def z(theta, phi): return sin(phi) * ( radius1 * sin(theta) + radius2) + center_z parametric = Parametric(x, y, z) matrix = Matrix() theta_step_range = Generator.get_step_range(0, 2 * pi, theta_step) phi_step_range = Generator.get_step_range(0, 2 * pi, phi_step) for i in theta_step_range: for j in phi_step_range: matrix += Matrix([parametric.get_point(i, j)]) return matrix
def get_sphere_pointmatrix(center_x, center_y, center_z, radius, theta_step=30, phi_step=30): """ Generates a Matrix of points representing the points on the 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 = Matrix() theta_step_range = Generator.get_step_range(0, 2 * pi, theta_step) phi_step_range = Generator.get_step_range(0, pi, phi_step) for i in theta_step_range: for j in phi_step_range: matrix += Matrix([parametric.get_point(i, j)]) return matrix
def get_polygon_edgematrix(center_x, center_y, radius, sides): """ Generates an EdgeMatrix of lines representing a regular polygon centered at the given points inscribed within a circle of the given radius. Parameters: center_x: int, the x coordinate of the center of the polygon center_y: int, the y coordinate of the center of the polygon radius: int, the radius of the circle sides: int, the number of sides in the polygon """ def x(t): return cos(t) * radius + center_x def y(t): return sin(t) * radius + center_y def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 2 * pi, sides) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_bezier_curve_edgematrix(p1, i1, i2, p2, step=30): """ Generates an EdgeMatrix of lines representing a bezier curve. Parameters: p1: list, the first endpoint of the bezier curve i1: list, the first influence point of the bezier curve i2: list, the second influence point of the bezier curve p2: list, the second endpoint of the bezier curve step: int (optional), the number of steps to use when drawing splines for the hermite curve """ def x(t): return Generator.get_bezier_function( p1[0], i1[0], i2[0], p2[0])(t) def y(t): return Generator.get_bezier_function( p1[1], i1[1], i2[1], p2[1])(t) def z(t): return 0 parametric = Parametric(x, y, z) edgematrix = EdgeMatrix() step_range = Generator.get_step_range(0, 1, step) for i in range(len(step_range) - 1): edgematrix.add_edge(parametric.get_point(step_range[i]), parametric.get_point(step_range[i + 1])) return edgematrix
def get_torus_pointmatrix(center_x, center_y, center_z, radius1, radius2, theta_step=30, phi_step=30): """ 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 """ def x(theta, phi): return radius1 * cos(theta) + center_x def y(theta, phi): return cos(phi) * (radius1 * sin(theta) + radius2) + center_y def z(theta, phi): return sin(phi) * (radius1 * sin(theta) + radius2) + center_z parametric = Parametric(x, y, z) matrix = Matrix() theta_step_range = Generator.get_step_range(0, 2 * pi, theta_step) phi_step_range = Generator.get_step_range(0, 2 * pi, phi_step) for i in theta_step_range: for j in phi_step_range: matrix += Matrix([parametric.get_point(i, j)]) return matrix
def get_sphere_pointmatrix(center_x, center_y, center_z, radius, theta_step=30, phi_step=30): """ Generates a Matrix of points representing the points on the 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 = Matrix() theta_step_range = Generator.get_step_range(0, 2 * pi, theta_step) phi_step_range = Generator.get_step_range(0, pi, phi_step) for i in theta_step_range: for j in phi_step_range: matrix += Matrix([parametric.get_point(i, j)]) return matrix