Clean up arcs to segments conversion.

From: Alexey Starikovskiy <[email protected]>


---

 src/emc/rs274ngc/gcodemodule.cc |   50 ++++++++++++---------------------------
 1 files changed, 15 insertions(+), 35 deletions(-)


diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc
index 53662a5..bbcff10 100644
--- a/src/emc/rs274ngc/gcodemodule.cc
+++ b/src/emc/rs274ngc/gcodemodule.cc
@@ -853,12 +853,6 @@ static bool get_attr(PyObject *o, const char *attr_name, const char *fmt, ...) {
     return result;
 }
 
-static void unrotate(double &x, double &y, double c, double s) {
-    double tx = x * c + y * s;
-    y = -x * s + y * c;
-    x = tx;
-}
-
 static void rotate(double &x, double &y, double c, double s) {
     double tx = x * c - y * s;
     y = x * s + y * c;
@@ -869,7 +863,7 @@ static PyObject *rs274_arc_to_segments(PyObject *self, PyObject *args) {
     PyObject *canon;
     double x1, y1, cx, cy, z1, a, b, c, u, v, w;
     double o[9], n[9], offset[9];
-    int rot, plane;
+    int rot, plane = 1;
     int X, Y, Z;
     double rotation_cos, rotation_sin;
     int max_segments = 128;
@@ -893,31 +887,24 @@ static PyObject *rs274_arc_to_segments(PyObject *self, PyObject *args) {
     if(!get_attr(canon, "offset_w", &offset[8])) return NULL;
 
     if(plane == 1) {
-        n[0] = x1;
-        n[1] = y1;
-        n[2] = z1;
         X=0; Y=1; Z=2;
     } else if(plane == 3) {
-        n[0] = y1;
-        n[1] = z1;
-        n[2] = x1;
         X=2; Y=0; Z=1;
     } else {
-        n[0] = z1;
-        n[1] = x1;
-        n[2] = y1;
         X=1; Y=2; Z=0;
     }
+    n[X] = x1;
+    n[Y] = y1;
+    n[Z] = z1;
     n[3] = a;
     n[4] = b;
     n[5] = c;
     n[6] = u;
     n[7] = v;
     n[8] = w;
-    for(int ax=0; ax<9; ax++) o[ax] -= offset[ax];
-    unrotate(o[0], o[1], rotation_cos, rotation_sin);
+    for (int ax=0; ax<9; ax++) o[ax] -= offset[ax];
+    rotate(o[0], o[1], rotation_cos, -rotation_sin);
 
-    double rad = hypot(o[X]-cx, o[Y]-cy);
     double theta1 = atan2(o[Y]-cy, o[X]-cx);
     double theta2 = atan2(n[Y]-cy, n[X]-cx);
 
@@ -931,26 +918,19 @@ static PyObject *rs274_arc_to_segments(PyObject *self, PyObject *args) {
     double rsteps = 1. / steps;
     PyObject *segs = PyList_New(steps);
 
-    double dtheta = theta2 - theta1;
-    double d[9] = {0, 0, 0, n[4]-o[4], n[5]-o[5], n[6]-o[6], n[7]-o[7], n[8]-o[8]};
-    d[Z] = o[Z] - n[Z];
-
-    double tx = cos(theta1) * rad, ty = sin(theta1)*rad, dc = cos(dtheta*rsteps), ds = sin(dtheta*rsteps);
-    for(int i=0; i<steps-1; i++) {
-        double f = i * rsteps;
-        double p[9];
+    double d[9], p[9];
+    d[Z] = (o[Z] - n[Z]) * rsteps;
+    for (int ax = 3; ax < 9; ++ax) d[ax] = (o[ax] - n[ax]) * rsteps;
+    double tx = o[X] - cx, ty = o[Y] - cy,
+           dc = cos((theta2 - theta1)*rsteps), ds = sin((theta2 - theta1)*rsteps);
+    for(int i = 0; i < steps - 1; ++i) {
         rotate(tx, ty, dc, ds);
         p[X] = tx + cx;
         p[Y] = ty + cy;
-        p[Z] = o[Z] + d[Z] * f;
-        p[3] = o[3] + d[3] * f;
-        p[4] = o[4] + d[4] * f;
-        p[5] = o[5] + d[5] * f;
-        p[6] = o[6] + d[6] * f;
-        p[7] = o[7] + d[7] * f;
-        p[8] = o[8] + d[8] * f;
+        p[Z] = o[Z] + d[Z] * i;
+        for (int ax = 3; ax < 9; ++ax) p[ax] = o[ax] + d[ax] * i;
         rotate(p[0], p[1], rotation_cos, rotation_sin);
-        for(int ax=0; ax<9; ax++) p[ax] += offset[ax];
+        for(int ax = 0; ax < 9; ++ax) p[ax] += offset[ax];
         PyList_SET_ITEM(segs, i,
             Py_BuildValue("ddddddddd", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]));
     }
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to