Esempio n. 1
0
 def test_circle_1(self):
     circle = SvCircle(Matrix(), 1.0)
     circle.u_bounds = (0, pi / 6)
     nurbs = circle.to_nurbs()
     cpts = nurbs.get_control_points()
     expected_cpts = np.array([[1.0, 0.0, 0.0], [1.0, 0.26794919, 0.0],
                               [0.8660254, 0.5, 0.0]])
     self.assert_numpy_arrays_equal(cpts, expected_cpts, precision=6)
Esempio n. 2
0
 def test_circle_2(self):
     circle = SvCircle(Matrix(), 1.0)
     t_max = pi + 0.3
     circle.u_bounds = (0, t_max)
     nurbs = circle.to_nurbs()
     ts = np.array([0, pi / 2, pi, t_max])
     points = nurbs.evaluate_array(ts)
     expected_points = circle.evaluate_array(ts)
     self.assert_numpy_arrays_equal(points, expected_points, precision=6)
Esempio n. 3
0
 def test_arc_2(self):
     pt1 = (-5, 0, 0)
     pt2 = (-4, 3, 0)
     pt3 = (-3, 4, 0)
     eq = circle_by_three_points(pt1, pt2, pt3)
     matrix = eq.get_matrix()
     arc = SvCircle(matrix, eq.radius)
     arc.u_bounds = (0.0, eq.arc_angle)
     nurbs = arc.to_nurbs()
     u_min, u_max = nurbs.get_u_bounds()
     self.assertEquals(u_min, 0, "U_min")
     self.assertEquals(u_max, eq.arc_angle, "U_max")
     startpoint = nurbs.evaluate(u_min)
     self.assert_sverchok_data_equal(startpoint.tolist(), pt1, precision=8)
     endpoint = nurbs.evaluate(u_max)
     self.assert_sverchok_data_equal(endpoint.tolist(), pt3, precision=8)
Esempio n. 4
0
def nurbs_revolution_surface(curve,
                             origin,
                             axis,
                             v_min=0,
                             v_max=2 * pi,
                             global_origin=True):
    my_control_points = curve.get_control_points()
    my_weights = curve.get_weights()
    control_points = []
    weights = []

    any_circle = SvCircle(Matrix(), 1)
    any_circle.u_bounds = (v_min, v_max)
    any_circle = any_circle.to_nurbs()
    # all circles with given (v_min, v_max)
    # actually always have the same knotvector
    # and the same number of control points
    n = len(any_circle.get_control_points())
    circle_knotvector = any_circle.get_knotvector()
    circle_weights = any_circle.get_weights()

    # TODO: vectorize with numpy? Or better let it so for better readability?
    for my_control_point, my_weight in zip(my_control_points, my_weights):
        eq = CircleEquation3D.from_axis_point(origin, axis, my_control_point)
        if abs(eq.radius) < 1e-8:
            parallel_points = np.empty((n, 3))
            parallel_points[:] = np.array(eq.center)  #[np.newaxis].T
        else:
            circle = SvCircle.from_equation(eq)
            circle.u_bounds = (v_min, v_max)
            nurbs_circle = circle.to_nurbs()
            parallel_points = nurbs_circle.get_control_points()
        parallel_weights = circle_weights * my_weight
        control_points.append(parallel_points)
        weights.append(parallel_weights)
    control_points = np.array(control_points)
    if global_origin:
        control_points = control_points - origin

    weights = np.array(weights)
    degree_u = curve.get_degree()
    degree_v = 2  # circle

    return SvNurbsSurface.build(curve.get_nurbs_implementation(), degree_u,
                                degree_v, curve.get_knotvector(),
                                circle_knotvector, control_points, weights)
Esempio n. 5
0
 def test_arc_3(self):
     pt1 = np.array((-4, 2, 0))
     pt2 = np.array((0, 2.5, 0))
     pt3 = np.array((4, 2, 0))
     eq = circle_by_three_points(pt1, pt2, pt3)
     #matrix = eq.get_matrix()
     arc = SvCircle(center=np.array(eq.center),
                    vectorx=np.array(pt1 - eq.center),
                    normal=eq.normal)
     arc.u_bounds = (0.0, eq.arc_angle)
     nurbs = arc.to_nurbs()
     u_min, u_max = nurbs.get_u_bounds()
     self.assertEquals(u_min, 0, "U_min")
     self.assertEquals(u_max, eq.arc_angle, "U_max")
     startpoint = nurbs.evaluate(u_min)
     self.assert_sverchok_data_equal(startpoint.tolist(), pt1, precision=6)
     endpoint = nurbs.evaluate(u_max)
     self.assert_sverchok_data_equal(endpoint.tolist(), pt3, precision=6)