I have seen a few questions about writing dxf files that contain arcs or circles. The processing dxf library treats these by breaking them down to lines which generates excessively long files. I recently ran across an old forum post where circles were generated but not arcs and the code was incomplete. I went back through the dxf documentation and found the needed information for creating arcs in dxf. Below is a modification of the example code from the old post, extending it to show how to create lines and arcs as well as circles. Page 86 of the autodesk dxf reference document discusses the format for ellipses, which I am sure can be treated in the same way. Points are discussed on page 123.
EDIT: Code for drawing an ellipse tacked on at the end.
This code does not use the dxf library and works in P2D.
String[] expDxf = {"0", "SECTION", "2","ENTITIES","0"};
String fileName = "file2.dxf";
float[] x = {10, 20, 30};
float[] y = {10, 50, 100};
float theta = 30; // beginning of arc in degrees
float phi = 160; // end of arc
float rad = 40; // radius
String layer = "0";
void dxfLine(float x0, float y0, float x1, float y1){
int oldLen = expDxf.length;
int newLen = (expDxf.length+16);
expDxf = expand(expDxf, newLen );
expDxf [oldLen] = "LINE";
expDxf [oldLen+1] = "8"; // layer name
expDxf [oldLen+2] = layer;
expDxf [oldLen+3] = "10"; // x position of start
expDxf [oldLen+4] = str(x0);
expDxf [oldLen+5] = "20"; // y position of start
expDxf [oldLen+6] = str(y0);
expDxf [oldLen+7] = "30"; // z position of start
expDxf [oldLen+8] = "0.0"; // z value is zero
expDxf [oldLen+9] = "11"; // x position of end
expDxf [oldLen+10] = str(x1);
expDxf [oldLen+11] = "21"; // y position of end
expDxf [oldLen+12] = str(y1);
expDxf [oldLen+13] = "31"; // z position of end
expDxf [oldLen+14] = "0.0"; // z value is zero
expDxf [oldLen+15] = "0";
}
void dxfCircle(float x, float y, float rad){ // , String layer) {
int oldLen = expDxf.length;
int newLen = (expDxf.length+12);
expDxf = expand(expDxf, newLen );
expDxf [oldLen] = "CIRCLE";
expDxf [oldLen+1] = "8"; // layer name
expDxf [oldLen+2] = "0";
expDxf [oldLen+3] = "10"; // x position of center
expDxf [oldLen+4] = str(x);
expDxf [oldLen+5] = "20"; // y position of center
expDxf [oldLen+6] = str(y);
expDxf [oldLen+7] = "30"; // z position of center
expDxf [oldLen+8] = "0.0";
expDxf [oldLen+9] = "40"; // radius
expDxf [oldLen+10] = str(rad);
expDxf [oldLen+11] = "0";
}
// note: theta and phi are the starting and ending angles of the arc
void dxfArc(float x, float y, float rad, float theta, float phi){
int oldLen = expDxf.length;
int newLen = (expDxf.length+16);
expDxf = expand(expDxf, newLen );
expDxf [oldLen] = "ARC";
expDxf [oldLen+1] = "8"; // layer name
expDxf [oldLen+2] = layer;
expDxf [oldLen+3] = "10"; // x position of center
expDxf [oldLen+4] = str(x);
expDxf [oldLen+5] = "20"; // y position of center
expDxf [oldLen+6] = str(y);
expDxf [oldLen+7] = "30"; // z position of center
expDxf [oldLen+8] = "0.0";
expDxf [oldLen+9] = "40"; // radius
expDxf [oldLen+10] = str(rad);
expDxf [oldLen+11] = "50"; // sstarting angle
expDxf [oldLen+12] = str(theta);
expDxf [oldLen+13] = "51"; // endng angle
expDxf [oldLen+14] = str(phi);
expDxf [oldLen+15] = "0";
}
void dxfEnd() {
expDxf = expand(expDxf, expDxf.length+3 );
expDxf[expDxf.length-3] = "ENDSEC";
expDxf[expDxf.length-2] = "0";
expDxf[expDxf.length-1] = "EOF" ;
saveStrings(fileName, expDxf);
}
void setup(){
size(100,100);
noLoop();
dxfLine(x[0],y[0],x[1],y[1]);
dxfCircle(x[0],y[0],rad);
dxfArc(x[1],y[1],rad*2,theta, phi);
dxfEnd();
}
EDIT: ok, here is a method for generating an ellipse:
////// x and y define the center of the ellipse,
///// endX and endY define the end of major axis,
///// ratio is the ratio of minor to major axis length
void dxfEllipse(float x, float y, float endX, float endY, float ratio){
int oldLen = expDxf.length;
int newLen = (expDxf.length+18);
expDxf = expand(expDxf, newLen );
expDxf [oldLen] = "ELLIPSE";
expDxf [oldLen+1] = "8"; // layer name
expDxf [oldLen+2] = layer;
expDxf [oldLen+3] = "10"; // x position of center
expDxf [oldLen+4] = str(x);
expDxf [oldLen+5] = "20"; // y position of center
expDxf [oldLen+6] = str(y);
expDxf [oldLen+7] = "30"; // z position of center
expDxf [oldLen+8] = "0.0";
expDxf [oldLen+9] = "11"; // x position of end of major axis
expDxf [oldLen+10] = str(endX);
expDxf [oldLen+11] = "21"; // y
expDxf [oldLen+12] = str(endY);
expDxf [oldLen+13] = "31"; // z
expDxf [oldLen+14] = "0.0";
expDxf [oldLen+15] = "40"; // ratio of axis lengths
expDxf [oldLen+16] = str(ratio);
expDxf [oldLen+17] = "0";
}