Use of rotation in add_image #629
-
Hi, I've been using ezdxf happily to generate drawings with attached images - thanks as always. Rotation has always been 0 degrees until now. I'm now looking at attaching images rotated by an arbitrary angle. I've been down a rabbit hole all day, because autocad LT (which I've used to date) and bricscad (testing a trial) both have their own oddities here (Autocad LT Mac rounds any angle given in the image attach dialog to the nearest degree. Bricscad mac rounds at the second decimal place in degrees, so 140.555 becomes 140.56.) ezdxf is rounding too, but it's taken a bit of digging to work out what's going on. The I gather that the dxf format specifies the scale and rotation of an attached image by giving x and y components of the edges of a pixel. ezdxf seems to round the pixel scale/angle components to 6 decimal places. I'm working with images with 2mm and 5mm pixels. In truth, our production drawings use mm as the base unit, and none of this is really important. For my testing I used metres by accident, perhaps because I'd picked a bricscad template that used metres. When working in metres, with images with pixels of 2mm side, the rounding of the pixel edge vectors under rotation has a non-negligible effect on scale and position. An angle of 140.555 degrees becomes 140.539. Testing with ezdxf like import ezdxf
doc = ezdxf.new(setup=True)
msp = doc.modelspace()
imdef = doc.add_image_def(
"plan_3spans_spans01to02.jpg",
size_in_pixel=(13250, 7000),
)
msp.add_image(imdef, (0, 0), size_in_units=(26.5, 14.0), rotation=140.555)
doc.saveas("ezdxf_generated.dxf") {Auto|Brics}CAD both save many more decimal places and/or significant figures - 15 or 16 significant figures in a couple of test files. More testing would be needed to know whether this is fixed decimal places, or fixed significant figures, or something else. Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The rotation isn't stored as angle. The DXF attributes |
Beta Was this translation helpful? Give feedback.
The rotation isn't stored as angle. The DXF attributes
u_pixel
andv_pixel
store the direction and size of a single pixel in the x- and y-direction of the image. I removed the rounding at the conversion from angle to vector in the factory methodadd_image
andezdxf
stores these vectors with max. precision now.