On Tue, 14 Jun 2011 12:01:25 -0700 (PDT), Junum <junshikum@gmail.com>
wrote:
> My questions are
> 1. I guess that a method defining a tetrahedron is wrong (i.e., px,
> py, pz).
> How can I define a 3D object consisting of several plane surfaces
> (e.g., cube) in IDLanROI?
Try the code below. "TetrahedronVertices" generates some polyhedron.
"test" checks whether a point falls within this polyhedron and plots
both.
As you can see, the point (green sphere) falls within the polyhedron
(red pyramid) although the IDLanROI says otherwise. I don't know
what's going on here ...
-----------------
function TetrahedronVertices,r=r,phideg=phideg
; http://www.cs.umbc.edu/~squire/reference/polyhedra.shtml#tet rahedron
;
; r: any radius in which the polyhedron is inscribed
; phideg: goes from north pole 90 to -90 degrees
vertices=dblarr(3,4)
if n_elements(r) eq 0 then r=1d else r=double(r)
if n_elements(phideg) eq 0 then phideg=-19.471220333d else
phideg=double(phideg)
phi = !dpi*phideg/180.
theta120 = !dpi*120./180.
vertices[*,0]=[0,0,r]
theta = 0.
for i=1,3 do begin
vertices[0,i]=r*cos(theta)*cos(phi)
vertices[1,i]=r*sin(theta)*cos(phi)
vertices[2,i]=r*sin(phi)
theta += theta120
endfor
return,vertices
end;function TetrahedronVertices
pro test
; Tetrahedron vertices
r=10
v=TetrahedronVertices(r=r)
; Close tetrahedron
v=v[*,[0,1,2,3,1,2,3]]
; Point
p=[0,0,0.]
; Inside/outside
object = Obj_New('IDLanROI', v)
case object->containspoints(0.1,0.1,0.1) of
0: print,'Exterior'
1: print,'Interior'
2: print,'On Edge'
3: print,'On vertex'
endcase
; Plot object
oModel = OBJ_NEW('IDLgrModel')
oXAxis = OBJ_NEW('IDLgrAxis',$
0,title=OBJ_NEW('IDLgrText','X'),range=[min(v[0,*])-1,max(v[ 0,*])+1])
oYAxis = OBJ_NEW('IDLgrAxis',$
1,title=OBJ_NEW('IDLgrText','Y'),range=[min(v[1,*])-1,max(v[ 1,*])+1])
oZAxis = OBJ_NEW('IDLgrAxis',$
2,title=OBJ_NEW('IDLgrText','Z'),range=[min(v[2,*])-1,max(v[ 2,*])+1])
oModel -> Add, [oXAxis,oYAxis,oZAxis]
oModel -> Add, OBJ_NEW('orb',radius=r/10.,pos=p, COLOR=[0,255,0])
oModel -> Add, OBJ_NEW('IDLgrPolygon',v,
COLOR=[255,0,0],ALPHA_CHANNEL=0.5)
oModel -> ROTATE, [1, 0, 0], -90
oModel -> ROTATE, [0, 1, 0], 30
oModel -> ROTATE, [1, 0, 0], 30
XOBJVIEW,oModel
end;pro test
|