comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Help in modifying code
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Help in modifying code [message #32748] Mon, 04 November 2002 07:20
jim.blackwell is currently offline  jim.blackwell
Messages: 11
Registered: November 2002
Junior Member
Hi,

Found this code in the archives. I don't recall who wrote it, but
here's the question. I have a dataset that I need to have represented
as a vector field (as this code does for a cube with vectors eminating
from one corner). The data file contains for each X, Y, Z point in
space 3 vector component values. I'd like to use this code, but am
having difficulty in figuring out how to modify it to read and use the
data file I have.

Any help would be appreciated

Jim Blackwell


----------------------------cut
here-------------------------------------------------------- --------------
function fx,x,y,z
xc=-0.2
yc=-0.2
zc=-0.2
r=sqrt((x-xc)^2+(y-yc)^2+(z-zc)^2)
return,(x-xc)/r^2
end

function fy,x,y,z
xc=-0.2
yc=-0.2
zc=-0.2
r=sqrt((x-xc)^2+(y-yc)^2+(z-zc)^2)
return,(y-yc)/r^2
end


function fz,x,y,z
xc=-0.2
yc=-0.2
zc=-0.2
r=sqrt((x-xc)^2+(y-yc)^2+(z-zc)^2)
return,(z-zc)/r^2
end

pro vectfield3d
;Create model to contain surface
omodel = OBJ_NEW('IDLgrModel')
;create vector field
n=6
range=1.0
fac=0.05
step=range/(n-1)
x=step*findgen(n)
y=x
z=x
vx=fltarr(n,n,n)
vy=vx
vz=vx
v=vx
x1=vx
y1=vx
z1=vx
m=n-1
for i=0,m do begin
for j=0,m do begin
for k=0,m do begin
vx(i,j,k)=fx(x(i),y(j),z(k))
vy(i,j,k)=fy(x(i),y(j),z(k))
vz(i,j,k)=fz(x(i),y(j),z(k))
endfor
endfor
endfor
for i=0,m do begin
for j=0,m do begin
for k=0,m do begin
x1(i,j,k)=x(i)+fac*vx(i,j,k)
y1(i,j,k)=y(j)+fac*vy(i,j,k)
z1(i,j,k)=z(k)+fac*vz(i,j,k)
endfor
endfor
endfor
; normalize field
mnx=min([min(x),min(x1)])
mxx=max([max(x),max(x1)])
mny=min([min(y),min(y1)])
mxy=max([max(y),max(y1)])
mnz=min([min(z),min(z1)])
mxz=max([max(z),max(z1)])
max1=max([mxx,mxy,mxz])
min1=min([mnx,mny,mnz])
x1=-1.0+2.0*(x1-min1)/(max1-min1)
y1=-1.0+2.0*(y1-min1)/(max1-min1)
z1=-1.0+2.0*(z1-min1)/(max1-min1)
x=-1.0+2.0*(x-min1)/(max1-min1)
y=-1.0+2.0*(y-min1)/(max1-min1)
z=-1.0+2.0*(z-min1)/(max1-min1)
; create field vectors
for i=0,m do begin
for j=0,m do begin
for k=0,m do begin
xs=[x1(i,j,k),x(i)]
ys=[y1(i,j,k),y(j)]
zs=[z1(i,j,k),z(k)]
opolyline = OBJ_NEW('IDLgrPolyline', xs,ys,zs, $
color=[255,0,0],thick=1,shading=0)
omodel -> ADD, opolyline
mesh_obj,4,verts,conn,Replicate(0.01 ,6,6)
T3d,/Reset
T3d, Translate=[x1(i,j,k),y1(i,j,k),z1(i,j,k)]
verts=Vert_T3d(verts)
oSphere=OBJ_NEW('IDLgrpolygon',
verts,poly=conn,COLOR=[255,0,0],style=0)
omodel -> ADD, oSphere
endfor
endfor
endfor
;create box
opolyline = OBJ_NEW('IDLgrPolyline',[-1.0,1.0],[-1.0,-1.0],[-1.0,-1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline',[-1.0,-1.0],[-1.0,-1.0],[-1.0,1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [-1.0,1.0],[-1.0,-1.0],[1.0,1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [1.0,1.0],[-1.0,-1.0],[-1.0,1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [1.0,1.0],[-1.0,1.0],[-1.0,-1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [1.0,1.0],[1.0,1.0],[-1.0,1.0], $
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [-1.0,-1.0],[-1.0,1.0],[1.0,1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline',[-1.0,-1.0],[-1.0,1.0],[-1.0,-1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [-1.0,-1.0],[1.0,1.0],[-1.0,1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [-1.0,1.0],[1.0,1.0],[1.0,1.0], $
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [1.0,1.0],[-1.0,1.0],[1.0,1.0], $
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline
opolyline = OBJ_NEW('IDLgrPolyline', [-1.0,1.0],[1.0,1.0],[-1.0,-1.0],
$
color=[0,255,0],thick=1,shading=0)
omodel -> ADD, opolyline

;Create a fixed light
ofixedlight = OBJ_NEW('IDLgrLight', TYPE = 1, $
LOCATION = [-1,-1,1], COLOR = [128,128,128])
omodel -> ADD, ofixedlight
;Create another fixed light
ofixedlight1 = OBJ_NEW('IDLgrLight', TYPE = 1, $
LOCATION = [-1,1,1], COLOR = [128,128,128])
omodel -> ADD, ofixedlight1
;Create movable light that goes with surface
olight = OBJ_NEW('IDLgrLight', TYPE = 2, LOCATION = [-1,-1,-1])

omodel -> ADD, olight
xobjview,omodel
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: VRML export in IDL
Next Topic: IDL --> C++ ?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:12:16 PDT 2025

Total time taken to generate the page: 0.00467 seconds