tetrahedron_grid.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. function tg = tetrahedron_grid ( n, t, ng )
  2. %*****************************************************************************80
  3. %
  4. %% TETRAHEDRON_GRID computes points on a tetrahedral grid.
  5. %
  6. % Discussion:
  7. %
  8. % The grid is defined by specifying the coordinates of an enclosing
  9. % tetrahedron T, and the number of subintervals each edge of the
  10. % tetrahedron should be divided into.
  11. %
  12. % Choosing N = 10, for instance, breaks each side into 10 subintervals,
  13. % and produces a grid of ((10+1)*(10+2)*(10+3))/6 = 286 points.
  14. %
  15. % Licensing:
  16. %
  17. % This code is distributed under the GNU LGPL license.
  18. %
  19. % Modified:
  20. %
  21. % 10 November 2011
  22. %
  23. % Author:
  24. %
  25. % John Burkardt - https://people.sc.fsu.edu/~jburkardt/m_src/tetrahedron_grid/tetrahedron_grid.html
  26. %
  27. % Parameters:
  28. %
  29. % Input, integer N, the number of subintervals.
  30. %
  31. % Input, real T(3,4), the vertices of the tetrahedron.
  32. %
  33. % Input, integer NG, the number of grid points.
  34. %
  35. % Output, real TG(3,NG), the tetrahedron grid points.
  36. %
  37. tg = zeros ( 3, ng );
  38. p = 0;
  39. for i = 0 : n
  40. for j = 0 : n - i
  41. for k = 0 : n - i - j
  42. l = n - i - j - k;
  43. p = p + 1;
  44. tg(1:3,p) = ( i * t(1:3,1) + j * t(1:3,2) ...
  45. + k * t(1:3,3) + l * t(1:3,4) ) / n;
  46. end
  47. end
  48. end
  49. return
  50. end