doc = ezdxf.new('R2010') msp = doc.modelspace() # The center of the pentagon should be (0, 2, 2), and the shape is # rotated around x-axis about 45 degree, to accomplish this I use an # UCS with z-axis (0, 1, 1) and an x-axis parallel to WCS x-axis. 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 ) # calculating corner points in local (UCS) coordinates points = [Vector.from_deg_angle((360 / 5) * n) for n in range(5)] # converting UCS into OCS coordinates ocs_points = list(ucs.points_to_ocs(points)) # LWPOLYLINE accepts only 2D points and has an separated DXF attribute elevation. # All points have the same z-axis (elevation) in OCS! elevation = ocs_points[0].z msp.add_lwpolyline( points=ocs_points, format='xy', # ignore z-axis dxfattribs={ 'elevation': elevation, 'extrusion': ucs.uz, 'closed': True, 'color': 1, })
def test_points_to_ocs(): ucs = UCS(ux=(0, 0, -1), uz=(1, 0, 0)) points = [(1, 2, 3), (4, 5, 6), (9, 8, 7)] expected = [ucs.to_ocs(p) for p in points] result = list(ucs.points_to_ocs(points)) assert result == expected