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_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_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