Sorceress

spring geometry

May 21st, 2016
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // spring geometry
  2. // by @_sorceress
  3.  
  4. C = 8.00; // number of coils in the spring
  5. L = 8.00; // length of the spring (this is what you want to vary)
  6. R = 1.00; // radius of the spring
  7. G = 0.15; // gauge of spring wire
  8.  
  9. ures = 10*C; // steps along spring wire
  10. vres = 10; // steps around spring wire
  11.  
  12. for(v=0; v<vres; v++) {
  13. vscale = 2*PI*v/vres;
  14. gr = G * cos(vscale) + R;
  15. gz = G * sin(vscale);
  16. for(u=0; u<ures; u++) {
  17. uscale = u/ures;
  18. x = gr * cos(2*PI*C*uscale);
  19. y = gr * sin(2*PI*C*uscale);
  20. z = gz + L * uscale;
  21. // Output vector (x,y,z) which you can use in a vertex array, or whatever
  22. }
  23. }
RAW Paste Data