Internal: 3D Scatter Plot Example With Object Graphics using orb object
Anonym
Topic:
3D Scatter Plot Example With Object Graphics
Example program:
; Object graphics example of a simple scatterplot. The plot
; is rotated and then zoomed in and out. The plot point symbol
; used is the orb object which is distributed with IDL and is
; located in the examples/object directory of the IDL
; installation.
;
PRO my3dplot
;Create a window and view tree:
mywindow = OBJ_NEW('IDLgrWindow', DIMENSIONS=[400,400])
myview = OBJ_NEW('IDLgrView',VIEWPLANE_RECT=[-1.,-1.,2.,2.], $
ZCLIP=[2.0,-2.0], COLOR=[100,100,150])
mymodel1 = OBJ_NEW('IDLgrModel')
mymodel2 = OBJ_NEW('IDLgrModel')
myXAxisText = OBJ_NEW('IDLgrText','X-Axis')
myYAxisText = OBJ_NEW('IDLgrText','Y-Axis')
myZAxisText = OBJ_NEW('IDLgrText','Z-Axis')
myxaxis = OBJ_NEW('IDLgrAxis',0,TITLE=myXAxisText,$
COLOR=[255,0,0], $
RANGE=[-10.,10.], $
xCOORD_CONV=[0.,.1], $
yCOORD_CONV=[0.,.1], $
zCOORD_CONV=[0.,.1])
mymodel1 -> Add, myxaxis
myyaxis = OBJ_NEW('IDLgrAxis',1,TITLE=myYAxisText,$
COLOR=[0,255,0], $
RANGE=[-10.,10.], $
xCOORD_CONV=[0.,.1], $
yCOORD_CONV=[0.,.1], $
zCOORD_CONV=[0.,.1])
mymodel1 -> Add, myyaxis
myzaxis = OBJ_NEW('IDLgrAxis',2,TITLE=myZAxisText,$
COLOR=[0,0,255], $
RANGE=[-10.,10.], $
xCOORD_CONV=[0.,.1], $
yCOORD_CONV=[0.,.1], $
zCOORD_CONV=[0.,.1])
mymodel1 -> Add, myzaxis
; Create a light source
mylight=OBJ_NEW('IDLGRLIGHT',COLOR=[255,250,250], $
TYPE=2,INTENSITY=.9,LOCATION=[1.,1.,1.])
mymodel2 -> ADD, mylight
myview -> ADD, mymodel1
myview -> ADD, mymodel2
myorbs=OBJARR(10) ; array to contain orb objects
;specify coordinate locations of orbs
loc= [[1.,2.,-3.],$
[-4.,5.,6.],$
[-7.,-8.,9.],$
[9.,8.,7.],$
[6.,5.,4.],$
[3.,-2.,1.],$
[1.,-3.,-5.],$
[-7.,9.,-2.],$
[4.,6.,8.],$
[0.,0.,0.]]
; label coords
labelLoc = loc + .5
; label the orbs
myLabels = OBJ_NEW('IDLgrText', $
['A','B','C','D','E','F','G','H','I','J'], $
LOCATIONS = labelLoc, $
xCOORD_CONV=[0.,.1], $
yCOORD_CONV=[0.,.1], $
zCOORD_CONV=[0.,.1])
mymodel1 -> ADD, myLabels
FOR I=0,9 DO BEGIN
; create orbs of specified radius and color
myorbs[i]=OBJ_NEW('orb',RADIUS=.5,$
XCOORD_CONV=[0,.1], $
YCOORD_CONV=[0,.1], $
ZCOORD_CONV=[0,.1], $
SHADING=1, $
DENSITY=.5, $ ;set the vertices density of object
COLOR=[255,255,0])
mymodel1 -> ADD, myorbs[i]
; position orbs in specified [x,y,z] locations
myorbs[i]->SETPROPERTY,POS=[loc[0,i],loc[1,i],loc[2,i]]
ENDFOR
;Rotate the model and draw view in a loop
FOR I=0,30 DO BEGIN
mymodel1 -> ROTATE, [1,1,1], 2
mywindow -> DRAW, myview
ENDFOR
;Zoom out
FOR I=0,5 DO BEGIN
mymodel1 -> SCALE,.75,.75,.75
mywindow -> DRAW, myview
ENDFOR
;Zoom back in
FOR I=0,5 DO BEGIN
mymodel1 -> SCALE,1.33,1.33,1.33
mywindow -> DRAW, myview
ENDFOR
END