Scripts/Stereo Plot

From J Wiki
Jump to navigation Jump to search

The stereo utility creates spatial view of 3D plot results.

require 'plot trig'

rotz_z_=: ] +/ .* ((cos,sin),:-@sin,cos)@[ , 0 0 1"_

stereo_z_=: 3 : 0
  'boxed 0'stereo y.
:
  vp=. 1.6 _2.3 1 [ angle=. 1r24p1
  pd'reset;sub 1 2;new;',x.,';viewpoint ',":vp
  pd y.
  pd'new;',x.,';viewpoint ',":angle rotz vp
  pd y.
  pd'show'
)
Xsin xcos stick.png
'type stick;boxed 0'stereo ((*sin) ; (*cos) ; *:)(8p1*i.%])1000

The idea was suggested by Devon McCormick, instructing how to view the result:

Once you've done this, bring up the two pictures side-by-side and view them as a stereo pair: blend the images by crossing your eyes and moving your head back until you have a merged, 3-D image in the center.

A few more examples

Xsin xcos asqrt.png
stereo ((*sin) ; (*cos) ; |@%:)(18p1*i:%])1000

The verb works essentially as plot, selecting the type of plot corresponding to the shape and type of the argument, and taking additional parameters at the left. It hides the box by default.

Sin x cos.png.png
stereo ([ ; ] ; sin@[ */ cos@])~(1p1*i:%])10

It is possible to modify series of pd definitions as in the Plot demo. For 3D/Lines it would look like this

u=. 0.5*steps 0 50p1 500
r=. sin steps (o. (,-.)0.1), 500
x=. r*sin u
y=. r*cos u
z=. 0.1*u
pd 'sub 1 2;new;boxed 0'
pd 'color red'
pd 'viewpoint ',":vp=. 1.6 1.9 1.25
pd 'viewsize 1'
pd x;y;z
pd 'new;boxed 0'
pd 'color red'
pd 'viewpoint ',":1r24p1 rotz vp
pd 'viewsize 1'
pd x;y;z
pd 'show'

3d line.png



Contributed by Oleg Kobchenko.