def test_points_to_wcs():
    ucs = PassTroughUCS()
    assert list(ucs.points_to_wcs([(1, 2, 3), (3, 4, 5)])) == [
        Vec3(1, 2, 3),
        Vec3(3, 4, 5),
    ]

    ucs2 = UCS()
    assert list(ucs.points_to_wcs([
        (1, 2, 3), (3, 4, 5)
    ])) == list(ucs2.points_to_wcs([(1, 2, 3), (3, 4, 5)]))
Exemplo n.º 2
0
import math
import ezdxf
from ezdxf.math import UCS

doc = ezdxf.new('R2010')
msp = doc.modelspace()

# using an UCS simplifies 3D operations, but UCS definition can happen later
# calculating corner points in local (UCS) coordinates without Vector class
angle = math.radians(360 / 5)
corners_ucs = [(math.cos(angle * n), math.sin(angle * n), 0) for n in range(5)]

# let's do some transformations by UCS
transformation_ucs = UCS().rotate_local_z(math.radians(15))  # 1. rotation around z-axis
transformation_ucs.shift((0, .333, .333))  # 2. translation (inplace)
corners_ucs = list(transformation_ucs.points_to_wcs(corners_ucs))

location_ucs = UCS(origin=(0, 2, 2)).rotate_local_x(math.radians(-45))
msp.add_polyline3d(
    points=corners_ucs,
    dxfattribs={
        'closed': True,
        'color': 1,
    }
).transform_to_wcs(location_ucs)

# Add lines from the center of the POLYLINE to the corners
center_ucs = transformation_ucs.to_wcs((0, 0, 0))
for corner in corners_ucs:
    msp.add_line(
        center_ucs, corner, dxfattribs={'color': 1}
Exemplo n.º 3
0
corners_ucs = [(math.cos(angle * n), math.sin(angle * n), 0) for n in range(5)]

# let's do some transformations
tmatrix = Matrix44.chain(  # creating a transformation matrix
    Matrix44.z_rotate(math.radians(15)),  # 1. rotation around z-axis
    Matrix44.translate(0, .333, .333),  # 2. translation
)
transformed_corners_ucs = tmatrix.transform_vertices(corners_ucs)

# transform UCS into WCS
ucs = UCS(
    origin=(0, 2, 2),  # center of pentagon
    ux=(1, 0, 0),  # x-axis parallel to WCS x-axis
    uz=(0, 1, 1),  # z-axis
)
corners_wcs = list(ucs.points_to_wcs(transformed_corners_ucs))

msp.add_polyline3d(
    points=corners_wcs,
    dxfattribs={
        'closed': True,
        'color': 1,
    })

# add lines from center to corners
center_wcs = ucs.to_wcs((0, .333, .333))
for corner in corners_wcs:
    msp.add_line(center_wcs, corner, dxfattribs={'color': 1})

ucs.render_axis(msp)
doc.saveas(OUT_DIR / 'ucs_polyline3d.dxf')
Exemplo n.º 4
0
draw(spline_points)
msp.add_text("Closed Cubic R12Spline", dxfattribs={
    'height': .1
}).set_pos(spline_points[0])
R12Spline(spline_points, degree=3, closed=True).render(msp,
                                                       segments=SEGMENTS,
                                                       dxfattribs={'color': 3})
if dwg.dxfversion > 'AC1009':
    msp.add_closed_spline(control_points=spline_points,
                          degree=3,
                          dxfattribs={'color': 4})

# place open cubic b-spline in 3D space
ucs = UCS(origin=(10, 3, 3), ux=(1, 0, 0),
          uz=(0, 1, 1))  # 45 deg rotated around x-axis
assert ucs.is_cartesian
draw(ucs.points_to_wcs(base_spline_points), extrusion=ucs.uz)
msp.add_text("Open Cubic R12Spline in 3D space",
             dxfattribs={
                 'height': .1,
                 'extrusion': ucs.uz,
             }).set_pos(ucs.to_ocs(base_spline_points[0]))
R12Spline(base_spline_points, degree=3,
          closed=False).render(msp,
                               segments=SEGMENTS,
                               ucs=ucs,
                               dxfattribs={'color': 3})

dwg.saveas(NAME)
print("drawing '%s' created.\n" % NAME)