Write circle in dxf with c++

Write circle in dxf with c++

Anonymous
Not applicable
1,902 Views
3 Replies
Message 1 of 4

Write circle in dxf with c++

Anonymous
Not applicable

Hi,

i am working on a c++ program, which writes a circle in dxf format. I am using 10, 20, 30 as center coordinates of my circle. This coordinates are OCS. In case i use the default extrusion direction (0,0,1) the center point is on the right place. But when I set the normal as extrusion direction, because I need a custom orientation, the center point shifts and my circle is therefore not anymore on the right place.

 

I read the documentation about circle dxf and also the part Arbitrary Axis Algorithm. I think I have to shift the center point somehow.
Unfortunately I do not understand which step I have to use to get the right center value (10, 20, 30).

Have anyone an idea what i am doing wrong?

0 Likes
1,903 Views
3 Replies
Replies (3)
Message 2 of 4

TheCADnoob
Mentor
Mentor

How are you determining that your circle moved?

 

The position in the entity DXF will change when you save your DXF file as the location after saving is a comparative location of the UCS and the OCS. 

 

https://www.autodesk.com/techpubs/autocad/acad2000/dxf/object_coordinate_systems_40ocs41_dxf_ab.htm

 

CADnoob

EESignature

0 Likes
Message 3 of 4

Ranjit_Singh
Advisor
Advisor

After applying a custom orientation (for example '(0.707 0.707 0.707) you can calc the new center point using

(setq etdata (entget (entlast))
newcp (trans '(10 20 30) 1 (entlast))); assuming it is the last entity drawn, else pass the ename

Now simply update the entity data

 

(entmod (subst (cons 10 newcp) (assoc 10 etdata) etdata))
0 Likes
Message 4 of 4

leeminardi
Mentor
Mentor

Here's some additional background information you may find helpful.

 

Let’s say you have a circle positioned at 1.11, 2.22, 3.33 with a radius 4.44.  The dxf code for this circle will be:

AcDbCircle

 10

1.11

 20

2.22

 30

3.33

 40

4.44

 

Since the circle lies in the XY plane we do not see the plane definition.

 

If the circle is rotated by +30° about the Y  axis with a base point at its center, the DXF code becomes:

AcDbCircle

 10

2.22

 20

0.7037118017992727

 30

3.43886459460218

 40

4.44

210

0.5

220

0.0

230

0.8660254037844387

 

Here we see that the normal vector to the circle is (DXF code 210,220,230)

0.5, 0.0, 0.86602…

 

This can easily be determined from sin(30), 0, cos(30)

 

To determine the OCS (Object Coordinate System) coordinates (dxf 10, 20, 30), AutoCAD’s Arbitrary Axis Algorithm must be used.

https://www.autodesk.com/techpubs/autocad/acad2000/dxf/arbitrary_axis_algorithm_dxf_ab.htm#XREF_2425...

 

I have created an Excel spreadsheet to calculates the OCS coordinates for a point given its WCS coordinates and a normal vector.  There are two possible alternatives for the x OCS axis. The one to use is dependent on the magnitude of the x and y values of the normal vector as defined in the Arbitrary Axis Algorithm.  The two option are shown in rows 10 and 11. The appropriate axis is shown in row 13 and the OCS y axis in row 14, and OCS z axis in row 15.

ocs.JPG

 

 

Since we wish to convert from the WCS to the OCS we invert the OCS matrix to yield the resulting matrix found in rows 18, 19, and 20.

 

Performing a matrix multiply of the WCS point with the inverted OCS matrix results in the OCS coordinates as shown in row 3.

 

Note, Excel includes matrix multiply and matrix inversion functions but does not include a vector cross product function so I added a VBA cross product function vCP.

Function vCP(v1 As Variant, v2 As Variant) As Variant

vCP = Array(v1(2) * v2(3) - v1(3) * v2(2), _

v1(3) * v2(1) - v1(1) * v2(3), _

v1(1) * v2(2) - v1(2) * v2(1))

End Function

 

The attached Excel file is a .xlms (macro-enabled) file.

 

 

 

 

 

lee.minardi