def test_roots_to_poly(self): roots = (1.0, 4.0, 5.0) p = sympyutils.roots_to_poly(roots) self.assertTrue(p.is_monic) root_to_count = sympy.roots(p) self.assertEqual(set(root_to_count.values()), set([1])) observed = set(root_to_count.keys()) expected = set(roots) for r_observed, r_expected in zip(sorted(observed), sorted(expected)): self.assertAlmostEqual(r_observed, r_expected)
def __init__(self): # this is basically like # f(x) = (x-2)(x-5)(x-7) # f(x) = x^3 - 14 x^2 + 59 x - 70 # f'(x) = 3 x^2 - 28 x + 59 # f''(x) = 6 x - 28 self.initial_t = 0.9 root_a = 1.0 root_b = 2.5 root_c = 3.5 self.final_t = 3.6 p3 = sympyutils.roots_to_poly((root_a, root_b, root_c)) p2 = p3.diff() p1 = p2.diff() self.polys = (p1, p2, p3) self.shape = interlace.CubicPolyShape(self.polys, self.initial_t, self.final_t)
def __init__(self): # this is basically like # f(x) = (x-2)(x-5)(x-7) # f(x) = x^3 - 14 x^2 + 59 x - 70 # f'(x) = 3 x^2 - 28 x + 59 # f''(x) = 6 x - 28 self.initial_t = 0.9 root_a = 1.0 root_b = 2.5 root_c = 3.5 self.final_t = 3.6 p3 = sympyutils.roots_to_poly((root_a, root_b, root_c)) p2 = p3.diff() p1 = p2.diff() self.polys = (p1, p2, p3) self.shape = interlace.CubicPolyShape( self.polys, self.initial_t, self.final_t)
def roots_to_differential_polys(roots): """ Construct a sequence of interlacing polynomials. The input is the collection of distinct roots of the highest degree polynomial in the sequence. @param roots: a collection of distinct roots @return: a sequence of interlacing polynomials """ sympy_t = sympy.abc.t if len(roots) != len(set(roots)): raise ValueError('expected distinct roots') p = sympyutils.roots_to_poly(roots) nroots = len(roots) polys = [p] for i in range(nroots-1): p = polys[-1].diff(sympy_t) polys.append(p) polys.reverse() return polys
def roots_to_differential_polys(roots): """ Construct a sequence of interlacing polynomials. The input is the collection of distinct roots of the highest degree polynomial in the sequence. @param roots: a collection of distinct roots @return: a sequence of interlacing polynomials """ sympy_t = sympy.abc.t if len(roots) != len(set(roots)): raise ValueError('expected distinct roots') p = sympyutils.roots_to_poly(roots) nroots = len(roots) polys = [p] for i in range(nroots - 1): p = polys[-1].diff(sympy_t) polys.append(p) polys.reverse() return polys
def get_scene(root_a, root_b, root_c, initial_t, final_t, intersection_radius, half_axis_radii): """ Define all of the bezier paths annotated with styles. @return: a list of strokes """ # define the strokes strokes = [] # define the half axis line segments xp_rad, xn_rad, yp_rad, yn_rad, zp_rad, zn_rad = half_axis_radii strokes.extend([ bpath_to_stroke(make_half_axis(0, +1, xp_rad), STYLE_X), bpath_to_stroke(make_half_axis(0, -1, xn_rad), STYLE_X), bpath_to_stroke(make_half_axis(1, +1, yp_rad), STYLE_Y), bpath_to_stroke(make_half_axis(1, -1, yn_rad), STYLE_Y), bpath_to_stroke(make_half_axis(2, +1, zp_rad), STYLE_Z), bpath_to_stroke(make_half_axis(2, -1, zn_rad), STYLE_Z) ]) # define the polynomial curve p3 = sympyutils.roots_to_poly((root_a, root_b, root_c)) p2 = p3.diff() p1 = p2.diff() shape = interlace.CubicPolyShape((p1, p2, p3), initial_t, final_t) strokes.append(bpath_to_stroke(shape.get_bezier_path(), STYLE_CURVE)) # define the orthocircles at curve-plane intersections axes = range(3) point_seqs = shape.get_orthoplanar_intersections() styles = (STYLE_X, STYLE_Y, STYLE_Z) for axis, point_seq, style in zip(axes, point_seqs, styles): for center in point_seq: bchunks = list( bezier.gen_bchunks_ortho_circle(center, intersection_radius, axis)) bpath = pcurve.BezierPath(bchunks) for b in bchunks: b.parent_ref = id(bpath) strokes.append(bpath_to_stroke(bpath, style)) return strokes
def get_scene(root_a, root_b, root_c, initial_t, final_t, intersection_radius, half_axis_radii): """ Define all of the bezier paths annotated with styles. @return: a list of strokes """ # define the strokes strokes = [] # define the half axis line segments xp_rad, xn_rad, yp_rad, yn_rad, zp_rad, zn_rad = half_axis_radii strokes.extend([ bpath_to_stroke(make_half_axis(0, +1, xp_rad), STYLE_X), bpath_to_stroke(make_half_axis(0, -1, xn_rad), STYLE_X), bpath_to_stroke(make_half_axis(1, +1, yp_rad), STYLE_Y), bpath_to_stroke(make_half_axis(1, -1, yn_rad), STYLE_Y), bpath_to_stroke(make_half_axis(2, +1, zp_rad), STYLE_Z), bpath_to_stroke(make_half_axis(2, -1, zn_rad), STYLE_Z)]) # define the polynomial curve p3 = sympyutils.roots_to_poly((root_a, root_b, root_c)) p2 = p3.diff() p1 = p2.diff() shape = interlace.CubicPolyShape((p1, p2, p3), initial_t, final_t) strokes.append(bpath_to_stroke(shape.get_bezier_path(), STYLE_CURVE)) # define the orthocircles at curve-plane intersections axes = range(3) point_seqs = shape.get_orthoplanar_intersections() styles = (STYLE_X, STYLE_Y, STYLE_Z) for axis, point_seq, style in zip(axes, point_seqs, styles): for center in point_seq: bchunks = list(bezier.gen_bchunks_ortho_circle( center, intersection_radius, axis)) bpath = pcurve.BezierPath(bchunks) for b in bchunks: b.parent_ref = id(bpath) strokes.append(bpath_to_stroke(bpath, style)) return strokes