Exemplo n.º 1
0
    def _arc_to_nurbs(self, t_min, t_max, implementation=SvNurbsMaths.NATIVE):
        alpha = t_max - t_min
        p0_x = cos(t_min)
        p0_y = sin(t_min)
        p2_x = cos(t_max)
        p2_y = sin(t_max)
        t_mid = 0.5 * (t_max + t_min)
        theta = 0.5 * alpha
        p1_r = 1.0 / cos(theta)
        p1_x = p1_r * cos(t_mid)
        p1_y = p1_r * sin(t_mid)

        control_points = np.array([[p0_x, p0_y, 0], [p1_x, p1_y, 0],
                                   [p2_x, p2_y, 0]])
        control_points = self.radius * control_points
        control_points = np.apply_along_axis(lambda v: self.matrix @ v, 1,
                                             control_points)
        control_points = self.center + control_points

        w1 = cos(theta)
        weights = np.array([1, w1, 1])
        degree = 2
        knotvector = sv_knotvector.generate(degree, 3)
        knotvector = sv_knotvector.rescale(knotvector, t_min, t_max)

        nurbs = SvNurbsMaths.build_curve(implementation, degree, knotvector,
                                         control_points, weights)

        if alpha > 2 * pi / 3:
            nurbs = nurbs.insert_knot(t_mid)

        return nurbs
Exemplo n.º 2
0
    def reparametrize(self, new_t_min, new_t_max):
        kv = self.get_knotvector()
        t_min, t_max = kv[0], kv[-1]
        if t_min == new_t_min and t_max == new_t_max:
            return self

        knotvector = sv_knotvector.rescale(kv, new_t_min, new_t_max)
        return SvNurbsCurve.build(self.get_nurbs_implementation(),
                                  self.get_degree(), knotvector,
                                  self.get_control_points(),
                                  self.get_weights())
Exemplo n.º 3
0
 def to_nurbs(self, implementation=SvNurbsMaths.NATIVE):
     u_min, u_max = self.get_u_bounds()
     knotvector = sv_knotvector.generate(1, 2)
     knotvector = sv_knotvector.rescale(knotvector, u_min, u_max)
     p1 = self.evaluate(u_min)
     p2 = self.evaluate(u_max)
     control_points = np.array([p1, p2])
     return SvNurbsMaths.build_curve(implementation,
                                     degree=1,
                                     knotvector=knotvector,
                                     control_points=control_points)
Exemplo n.º 4
0
 def reparametrize(self, new_t_min, new_t_max):
     knotvector = sv_knotvector.rescale(self.get_knotvector(), new_t_min, new_t_max)
     return SvNurbsCurve.build(self.get_nurbs_implementation(),
             self.get_degree(), knotvector, self.get_control_points(), self.get_weights())