Advertisement
Guest User

Untitled

a guest
Mar 7th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. // This is a component for Linuxcnc HAL
  2. // Copyright 2020 Sam Sokolik <samcoinc@gmail.com>
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. component polygon "Create a spindle synced motion that carves a polygon using eoffset inputs";
  18.  
  19. pin in unsigned numsides=3 "Number of sides in the polygon";
  20. pin in float inscribedradius=1 "inscribed radius of the polygon";
  21. pin in float cutterdiam "cutter diameter";
  22. pin in float eoffsetscale "scale that eoffset is set to.";
  23. pin in float spindlepos "Spindle position scaled to 1 per rev";
  24. pin out float spindlerad "Spindle postion in radians";
  25. pin out float polyradius "radious of the polygon at given spindle position";
  26. pin out float xoffset "x offset to send to offset componant";
  27. pin out float yoffset "y offset to send to the offset componant";
  28. pin out signed xeoffset "x eoffset output";
  29. pin out signed yeoffset "y eoffset output";
  30.  
  31.  
  32. function _;
  33. license "GPL";
  34. ;;
  35. #include <rtapi_math.h>
  36. #define PI 3.14159265358979323846
  37. float spinang;
  38. float scale;
  39.  
  40.  
  41. //formual I found is for circumscribed - convert to inscribed - makes more sense.
  42. scale=inscribedradius/cos(PI/numsides);
  43.  
  44.  
  45.  
  46. spinang = (spindlepos - (int)(spindlepos))*2*PI;
  47. polyradius = (cos(PI/numsides)/cos((fmod(spinang, (2*PI/numsides))-PI/numsides)))*scale-cutterdiam;
  48.  
  49. xoffset = cos(spinang)*polyradius;
  50. yoffset = sin(spinang)*polyradius;
  51.  
  52. xeoffset = xoffset * eoffsetscale;
  53. yeoffset = yoffset * eoffsetscale;
  54.  
  55. spindlerad = spinang;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement