NB. plotting 3-coord points
NB. 08/16/05 Oleg Kobchenko

require 'plot'

cut=: <"2 @ (0 1&|:)  NB. 3-array to list of boxed matrices

cubic=: 3 : 0         NB. unit 3-cube
  v   =. 2 2 2#: i.8
  ndx =. 0 2 6 4, 4 6 7 5, 1 5 7 3, 0 1 3 2, 2 3 7 6,: 0 4 5 1
  ndx { v
)

cubes=: [: cut  cubic ,/@:(+"1"_ 1) ] NB.  unit cubes shited by list of 3-coords

plotcubes=: 'poly'"_ plot cubes       NB. 3d plot of list of 3-coords

view3d=: [: plotcubes ($ #: I.@,)     NB. 3d boolean viewmat

randcubes=: 4 : '3 (# (#: ?) y.&#@^~) x.'   NB. y 3-coords from 0..x

0 : 0
  plotcubes 5 randcubes 10
  plotcubes 5 randcubes 20
  plotcubes 10 randcubes 100
  plotcubes 30 randcubes 1000
  plotcubes 100 randcubes 10000

  ]CUBES=: 5 randcubes 10
  cut QUBES=: 1(<"1 CUBES)}5 5 5$0  NB. coord to boolean 3-cube
  (/:~CUBES) -: ($ #: I.@,) QUBES
  plotcubes CUBES
  view3d QUBES

  view3d 1>? (3#5)$10
  view3d 3>? (3#20)$100
)