Exemplo n.º 1
0
def test_normal_vector_for_3_points():
    # normal_vector_3p(a, b, c)
    # a->b = v1
    # a->c = v2
    o = Vector(0, 0, 0)
    assert normal_vector_3p(o, X_AXIS, Y_AXIS) == Z_AXIS
    assert normal_vector_3p(o, Y_AXIS, X_AXIS) == -Z_AXIS
    assert normal_vector_3p(o, Z_AXIS, X_AXIS) == Y_AXIS
    assert normal_vector_3p(o, X_AXIS, Z_AXIS) == -Y_AXIS
    assert normal_vector_3p(o, Y_AXIS, Z_AXIS) == X_AXIS
    assert normal_vector_3p(o, Z_AXIS, Y_AXIS) == -X_AXIS
Exemplo n.º 2
0
    def render_normals(
        self,
        layout: "GenericLayoutType",
        length: float = 1,
        relative=True,
        dxfattribs=None,
    ):
        """Render face normals as :class:`~ezdxf.entities.Line` entities into
        `layout`, useful to check orientation of mesh faces.

        Args:
            layout: :class:`~ezdxf.layouts.BaseLayout` object
            length: visual length of normal, use length < 0 to point normals in
                opposite direction
            relative: scale length relative to face size if ``True``
            dxfattribs: dict of DXF attributes e.g. ``{'layer': 'normals', 'color': 6}``

        """
        dxfattribs = dict(dxfattribs) if dxfattribs else {}
        for face in self.faces_as_vertices():
            count = len(face)
            if count < 3:
                continue
            center = sum(face) / count
            i = 0
            n = NULLVEC
            while i <= count - 3:
                n = normal_vector_3p(face[i], face[i + 1], face[i + 2])
                if n != NULLVEC:  # not colinear vectors
                    break
                i += 1

            if relative:
                _length = (face[0] - center).magnitude * length
            else:
                _length = length
            layout.add_line(center,
                            center + n * _length,
                            dxfattribs=dxfattribs)
Exemplo n.º 3
0
def test_normal_vector_for_3_points(a, b, c, r):
    assert normal_vector_3p(a, b, c) == r