Talk:Scripts/Plot 3D

From J Wiki
Jump to navigation Jump to search

viewmat 3d

Here's variation on view3d which displays an array of cubes using viewmat style coloring (except having 0 be transparent):

require'viewmat'
viewmat3d=: {{
  '' viewmat3d y
:
  ndx=. ($ #: I.@,) 0~:y
  o=. /: +/"1]1 _1 1*"1 ndx
  MYCOLOR_jzplot_=. 6#(3#256)#:;;{.x getvm1_jviewmat_ o{(,y)-.0
  pd 'new;type poly;edgecolor gray; color MYCOLOR'
  pd"1 o{|:_6<\&> cubes ndx
  pd'show'
}}

viewmat3d_z_=: viewmat3d_jzplot_

And, to exercise it, here's an example involving a polycube (except with each cube colored uniquely to aid in visualizing rotations - normally in polycube contexts each cube is only distinguished by its position relative to its neighbors):

rotx=: |."2@(2 1&|:)  NB. rotate in the yz plane about the x axis
roty=: |.@(1 0 2&|:)  NB. rotate in the xz plane about the y axis
rotz=: |.@(2 1 0&|:)  NB. rotate in the xy plane about the z axis

pc=: 2 2 2$1 0 0 0 2 3 0 4

viewmat3d pc
viewmat3d rotx pc
viewmat3d roty pc
viewmat3d rotz pc
NB...

Remember that jhs or the j playground gives you persistent (inline) plots where jqt would update the plot window showing you only the most recent plot.