John Boccio wrote:
>
> Hi,
>
> Is there any straightforward way to plot
> directed arrows representing a vector field
> in 3 dimensions?
>
> Anyone have a sample code for direct graphics?
> using IDLgrpolyline?
>
> Thanks,
>
> John Boccio
> boccio@swarthmore.edu
Here is a small sample function I extracted from one of my programs.
I simplified it and did not test it, but I think you can get the idea.
The 'trick' is that the top of the vectors consist of two more
IDLgrPolyline
objects which are thicker than the rest of the vector to fake an arrow.
Another thicker part is drawn at the actual position of the vector
(the middle of the vector line here).
With this you save the need to caculate the projection for the vector
top.
I think therefore this gives not the nicest vectors, but it should be
quite fast.
Just add the returned objarr to a IDLgrModel.
Hope this is helpful.
:-) marc
;; ---
;; vectorPosition, vectorDirection: [3,numVectors] float arrays
;; colorArray: [3,numVectors] byte array for color of each vector
function sample,vectorPosition,vectorDirection,colorArray
vectorObj=objarr(4)
line1=[[vectorPosition[*,*]-vectorDirection[*,*]],$
[vectorPosition[*,*]+vectorDirection[*,*]]]
linkList=intarr(3,numPlot)
linkList[0,*]=2
linkList[1,*]=indgen(numPlot)
linkList[2,*]=indgen(numPlot)+numPlot
;; if we do not do this, polyline thinks we are using colortable
if numVectors eq 1 then vertColors=[[vertColors],[vertColors]]
line2=[[vectorPosition[*,*]+vectorDirection[*,*]*0.7],[vecto rPosition[*,*]+vectorDirection[*,*]*.8]]
line3=[[vectorPosition[*,*]+vectorDirection[*,*]*0.8],[vecto rPosition[*,*]+vectorDirection[*,*]*.9]]
line4=[[vectorPosition[*,*]-vectorDirection[*,*]*0.05],[vect orPosition[*,*]+vectorDirection[*,*]*.05]]
vectorObj[0]=obj_new('IDLgrPolyline',$
line1,$
POLYLINES=linkList,$
VERT_COLORS=vertColors,$
THICK=arrowThickness,$
COLOR=colorArray)
vectorObj[1]=obj_new('IDLgrPolyline',$
line2,$
POLYLINES=linkList,$
VERT_COLORS=vertColors,$
THICK=arrowThickness*4,$
COLOR=colorArray)
vectorObj[2]=obj_new('IDLgrPolyline',$
line3,$
POLYLINES=linkList,$
VERT_COLORS=vertColors,$
THICK=arrowThickness*2,$
COLOR=colorArray)
vectorObj[3]=obj_new('IDLgrPolyline',$
line4,$
POLYLINES=linkList,$
VERT_COLORS=vertColors,$
THICK=arrowThickness*2,$
COLOR=colorArray)
return,vectorObj
end
|