Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. //agoramachina 2019
  2.  
  3. $fn=20;
  4. n = 6;
  5. radius = 50;
  6. height = 2;
  7.  
  8. summon_circle();
  9.  
  10. // Generate matrix of n points
  11. function points(n) = [
  12. for (i=[1:n+1])
  13. [radius*cos(i*(360/n)), radius*sin(i*(360/n)),0]
  14. ];
  15.  
  16. // Find unit vector with direction v. Fails if v=[0,0,0].
  17. function unit(v) = norm(v)>0 ? v/norm(v) : undef;
  18.  
  19. // Find the transpose of a rectangular matrix
  20. function transpose(m) =
  21. [ for(j=[0:len(m[0])-1]) [ for(i=[0:len(m)-1]) m[i][j] ] ];
  22.  
  23. // Identity matrix with dimension n
  24. function identity(n) = [for(i=[0:n-1]) [for(j=[0:n-1]) i==j ? 1 : 0] ];
  25.  
  26. // Computes the rotation with minimum angle that brings a to b
  27. // Fails if a and b are opposed to each other
  28. function rotate_from_to(a,b) =
  29. let( axis = unit(cross(a,b)) )
  30. axis*axis >= 0.99 ?
  31. transpose([unit(b), axis, cross(axis, unit(b))]) *
  32. [unit(a), axis, cross(axis, unit(a))] :
  33. identity(3);
  34.  
  35. // Given points p0 and p1, draw a thin cylinder with its
  36. // bases at p0 and p1
  37. module line(p0, p1, diameter=1) {
  38. v = p1-p0;
  39. translate(p0)
  40. multmatrix(rotate_from_to([0,0,1],v))
  41. cylinder(d=diameter, h=norm(v));
  42. }
  43.  
  44. module summon_circle(){
  45. for (i=[0:n]){
  46. for (j=[0:n]){
  47. line (points(n)[i], points(n)[j], diameter=2);
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement