DXF image entity group code explanation

1.6k views Asked by At

I'm working on a Delphi class to import/export some kind of entities from DXF file. I'd like add support for Image entity but I don't understand some group codes.

I'm using official DXF guide reference (2002): http://www.autodesk.com/techpubs/autocad/dxf/dxf2002.pdf

I have understand the group codes 10, 20 and 30, there are the "Insertion point" and work like any other entities.

The problem are group codes: -11, 21 and 31: U-vector of a single pixel (points along the visual bottom of the image, starting at the insertion point) (in WCS);

-12, 22 and 32: V-vector of a single pixel (points along the visual left side of the image, starting at the insertion point) (in WCS);

I think DXF use it for scale and rotation but I don't have understand how.

Thanks

1

There are 1 answers

4
Stewbob On BEST ANSWER

These group codes are used for controlling the rotation and scale of the image.

Group codes 10, 20 and 30 control the insertion point of the lower left corner of your image.

The group codes 11, 21 and 31 are used to define a vector in 3D space that is the endpoint of a line whose start point is assumed to be 0,0,0, regardless of the origin point of the image. These group codes describe a relative vector.

This relative vector (for a scale factor of 1) is constrained by a circle whose radius is the square root of 1/8, or 0.352733677...

For example, an image inserted with no rotation, and a scale factor of 1, would have 11, 21, 31 group code values of 0.352733677,0,0 respectively.

An image inserted with no rotation, and a scale factor of 2, would have 11, 21, 31 group code values of 0.7054673542,0,0 respectively.

An image inserted with a 45 degree rotation and a scale factor of 1, would have 11, 21, 31 group codes of 0.25,0.25,0 respectively. Which is an oddly even number, but that's the way the math works out.

The scale factor is a multiplier of the circle whose radius is sqrt(1/8). Once you have this radius based on the scale factor, you can determine the '11' and '21' values using sin and cos of the rotation angle.

The 12, 22, 32 group codes have similar values, but for the left edge of the image.
The same math would be used to determine their values. It seems like over-constraining the image, but that's the way the specification works.

EDIT

The above answer is only valid for a raster image saved at 72 dpi and then inserted into a metric (millimeter scale) drawing.

The formula for figuring out what the proper value (for a scale factor of 1 when inserting the image in the AuoCAD drawing) in the '11' group code, for example, is:

(drawing units per inch) / (dpi of image)

In a metric dxf drawing that uses millimeters as the drawing units, and a raster image saved at 72 dpi, the scale factor would be 25.4/72 = .35277778

In a metric dxf drawing that uses millimeters as the drawing units, and a raster image saved at 96 dpi, the scale factor would be 25.4/96 = .26458333

In an imperial dxf drawing that uses inches as the drawing units, and a raster image saved at 72 dpi, the scale factor would be 1/72 = .013888888.

In an imperial dxf drawing that uses inches as the drawing units, and a raster image saved at 96 dpi, the scale factor would be 1/96 = .010416667.

When the dxf file is then opened in a program like AutoCAD, the raster image is drawn at the scale factor shown above, so our first example would be drawn at a size of width of image in pixels * scale factor in 11, which for a 100x100px image, would be 35.2778 mm.