Beispiel #1
0
 def test_cube_vertices_returns_vertices_in_counter_clockwise_order(self):
     bbox = BoundingBox([(0, 0, 0), (1, 2, 3)])
     assert bbox.cube_vertices() == Vec3.tuple([
         (0, 0, 0),  # bottom layer
         (1, 0, 0),
         (1, 2, 0),
         (0, 2, 0),
         (0, 0, 3),  # top layer
         (1, 0, 3),
         (1, 2, 3),
         (0, 2, 3),
     ])
Beispiel #2
0
def subdivide_ngons(
    faces: Iterable[Sequence["AnyVec"]],
) -> Iterable[Tuple[Vec3, ...]]:
    """Yields only triangles or quad faces, subdivides ngons into triangles.

    Args:
        faces: iterable of faces as sequence of :class:`Vec2` and
            :class:`Vec3` objects

    """
    for face in faces:
        if len(face) < 5:
            yield Vec3.tuple(face)
        else:
            mid_pos = Vec3.sum(face) / len(face)
            for index, vertex in enumerate(face):
                yield face[index - 1], vertex, mid_pos
Beispiel #3
0
def cubic_bezier_interpolation(
        points: Iterable['Vertex']) -> Iterable[Bezier4P]:
    """ Returns an interpolation curve for given data `points` as multiple cubic
    Bézier-curves. Returns n-1 cubic Bézier-curves for n given data points,
    curve i goes from point[i] to point[i+1].

    Args:
        points: data points

    .. versionadded:: 0.13

    """
    from ezdxf.math import tridiagonal_matrix_solver
    # Source: https://towardsdatascience.com/b%C3%A9zier-interpolation-8033e9a262c2
    points = Vec3.tuple(points)
    if len(points) < 3:
        raise ValueError('At least 3 points required.')

    num = len(points) - 1

    # setup tri-diagonal matrix (a, b, c)
    b = [4.0] * num
    a = [1.0] * num
    c = [1.0] * num
    b[0] = 2.0
    b[num - 1] = 7.0
    a[num - 1] = 2.0

    # setup right-hand side quantities
    points_vector = [points[0] + 2.0 * points[1]]
    points_vector.extend(2.0 * (2.0 * points[i] + points[i + 1])
                         for i in range(1, num - 1))
    points_vector.append(8.0 * points[num - 1] + points[num])

    # solve tri-diagonal linear equation system
    solution = tridiagonal_matrix_solver((a, b, c), points_vector)
    control_points_1 = Vec3.list(solution.rows())
    control_points_2 = [
        p * 2.0 - cp for p, cp in zip(points[1:], control_points_1[1:])
    ]
    control_points_2.append((control_points_1[num - 1] + points[num]) / 2.0)

    for defpoints in zip(points, control_points_1, control_points_2,
                         points[1:]):
        yield Bezier4P(defpoints)
Beispiel #4
0
 def __init__(self, defpoints: Iterable["Vertex"]):
     self._defpoints: Sequence[Vec3] = Vec3.tuple(defpoints)