You should borrow the algorithm completely -- not doing trigonometry
in a cycle helps.
Regards,
Alex.
Jeff Epler пишет:
> this increases timings a little bit (including in the unrotated case), but
> correct is much better than fast in this case
> ---
> src/emc/rs274ngc/gcodemodule.cc | 47 ++++++++++++++++++++++----------------
> 1 files changed, 27 insertions(+), 20 deletions(-)
>
> diff --git a/src/emc/rs274ngc/gcodemodule.cc b/src/emc/rs274ngc/gcodemodule.cc
> index 051bbe1..7a4a7d7 100644
> --- a/src/emc/rs274ngc/gcodemodule.cc
> +++ b/src/emc/rs274ngc/gcodemodule.cc
> @@ -846,6 +846,12 @@ 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;
> @@ -880,31 +886,29 @@ static PyObject *rs274_arc_to_segments(PyObject *self,
> PyObject *args) {
> if(!get_attr(canon, "offset_w", &offset[8])) return NULL;
>
> if(plane == 1) {
> - rotate(x1, y1, rotation_cos, rotation_sin);
> - rotate(cx, cy, rotation_cos, rotation_sin);
> - n[0] = x1 + offset[0];
> - n[1] = y1 + offset[1];
> - n[2] = z1 + offset[2];
> + n[0] = x1;
> + n[1] = y1;
> + n[2] = z1;
> X=0; Y=1; Z=2;
> } else if(plane == 3) {
> - n[0] = y1 + offset[0];
> - n[1] = z1 + offset[1];
> - n[2] = x1 + offset[2];
> + n[0] = y1;
> + n[1] = z1;
> + n[2] = x1;
> X=2; Y=0; Z=1;
> } else {
> - n[0] = z1 + offset[0];
> - n[1] = x1 + offset[1];
> - n[2] = y1 + offset[2];
> + n[0] = z1;
> + n[1] = x1;
> + n[2] = y1;
> X=1; Y=2; Z=0;
> }
> - cx += offset[X];
> - cy += offset[Y];
> - n[3] = a + offset[3];
> - n[4] = b + offset[4];
> - n[5] = c + offset[5];
> - n[6] = u + offset[6];
> - n[7] = v + offset[7];
> - n[8] = w + offset[8];
> + 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);
>
> double rad = hypot(o[X]-cx, o[Y]-cy);
> double theta1 = atan2(o[Y]-cy, o[X]-cx);
> @@ -936,10 +940,13 @@ static PyObject *rs274_arc_to_segments(PyObject *self,
> PyObject *args) {
> p[6] = o[6] + d[6] * f;
> p[7] = o[7] + d[7] * f;
> p[8] = o[8] + d[8] * f;
> -
> + rotate(p[0], p[1], rotation_cos, rotation_sin);
> + 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]));
> }
> + for(int ax=0; ax<9; ax++) n[ax] += offset[ax];
> + rotate(n[0], n[1], rotation_cos, rotation_sin);
> PyList_SET_ITEM(segs, steps,
> Py_BuildValue("ddddddddd", n[0], n[1], n[2], n[3], n[4], n[5], n[6],
> n[7], n[8]));
> return segs;
>
------------------------------------------------------------------------------
Download Intel® 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