void ImpExpDxfWrite::exportArc(BRepAdaptor_Curve& c) { gp_Circ circ = c.Circle(); gp_Pnt p = circ.Location(); double center[3] = {0,0,0}; gPntToTuple(center, p); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); double start[3]; gPntToTuple(start, s); gp_Pnt m = c.Value((l+f)/2.0); gp_Pnt e = c.Value(l); double end[3] = {0,0,0}; gPntToTuple(end, e); gp_Vec v1(m,s); gp_Vec v2(m,e); gp_Vec v3(0,0,1); double a = v3.DotCross(v1,v2); bool dir = (a < 0) ? true: false; writeArc(start, end, center, dir ); }
void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { gp_Circ circ = c.Circle(); const gp_Pnt& p= circ.Location(); double r = circ.Radius(); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); gp_Pnt m = c.Value((l+f)/2.0); gp_Pnt e = c.Value(l); gp_Vec v1(m,s); gp_Vec v2(m,e); gp_Vec v3(0,0,1); double a = v3.DotCross(v1,v2); // a full circle if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) { out << "<circle cx =\"" << p.X() << "\" cy =\"" << p.Y() << "\" r =\"" << r << "\" />"; } // arc of circle else { // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths char xar = '0'; // x-axis-rotation char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r << " " << r << " " << xar << " " << las << " " << swp << " " << e.X() << " " << e.Y() << "\" />"; } }
void ImpExpDxfWrite::exportCircle(BRepAdaptor_Curve& c) { gp_Circ circ = c.Circle(); gp_Pnt p = circ.Location(); double center[3] = {0,0,0}; gPntToTuple(center, p); double radius = circ.Radius(); writeCircle(center, radius); }
void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { gp_Circ circ = c.Circle(); //const gp_Ax1& axis = c->Axis(); const gp_Pnt& p= circ.Location(); double r = circ.Radius(); double f = c.FirstParameter(); double l = c.LastParameter(); gp_Pnt s = c.Value(f); gp_Pnt m = c.Value((l+f)/2.0); gp_Pnt e = c.Value(l); gp_Vec v1(m,s); gp_Vec v2(m,e); gp_Vec v3(0,0,1); double a = v3.DotCross(v1,v2); // a full circle if (s.SquareDistance(e) < 0.001) { //out << "<circle cx =\"" << p.X() << "\" cy =\"" //<< p.Y() << "\" r =\"" << r << "\" />"; out << 0 << endl; out << "CIRCLE" << endl; out << 8 << endl; // Group code for layer name out << "sheet_layer" << endl; // Layer number out << 10 << endl; // Centre X out << p.X() << endl; // X in WCS coordinates out << 20 << endl; out << p.Y() << endl; // Y in WCS coordinates out << 30 << endl; out << 0 << endl; // Z in WCS coordinates-leaving flat out << 40 << endl; // out << r << endl; // Radius } // arc of circle else { // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths /*char xar = '0'; // x-axis-rotation char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "<path d=\"M" << s.X() << " " << s.Y() << " A" << r << " " << r << " " << xar << " " << las << " " << swp << " " << e.X() << " " << e.Y() << "\" />";*/ double ax = s.X() - p.X(); double ay = s.Y() - p.Y(); double bx = e.X() - p.X(); double by = e.Y() - p.Y(); double start_angle = atan2(ay, ax) * 180/D_PI; double end_angle = atan2(by, bx) * 180/D_PI; if(a > 0){ double temp = start_angle; start_angle = end_angle; end_angle = temp;} out << 0 << endl; out << "ARC" << endl; out << 8 << endl; // Group code for layer name out << "sheet_layer" << endl; // Layer number out << 10 << endl; // Centre X out << p.X() << endl; // X in WCS coordinates out << 20 << endl; out << p.Y() << endl; // Y in WCS coordinates out << 30 << endl; out << 0 << endl; // Z in WCS coordinates out << 40 << endl; // out << r << endl; // Radius out << 50 << endl; out << start_angle << endl; // Start angle out << 51 << endl; out << end_angle << endl; // End angle } }