5720
Example of how to generate an ellipsoid with IDL 8 Graphics
Topic:
This article provides an example of how you can generate an ellipsoid using the IDL 8 function graphics. If you run the MAIN level program included in the example, the output should appear like the image below:

Discussion:
An example program called "dj_ellipsoid_ng.pro" that generates an ellipsoid is shown below. "dj_ellipsoid_ng" is a procedure that accepts 3 parameters (A,B,C). It then generates a grid of theta and phi values and then uses the equation for an ellipsoid to determine the radius value for each point on the grid. It then uses the MESH_OBJ function to generate the vertices and polygons of the ellipsoid. Finally, the PLOT3D and POLYGON function are used to generate a visual of the ellipsoid.
function get_rad, theta, phi, a,b,c
compile_opt idl2
;use the formula for the ellipsoid to
;determine the radius for various values
;of theta and phi.
radius = sqrt(((a*b*c)^2)/( $
b^2*c^2*(cos(theta)^2)*(sin(phi)^2)+ $
a^2*c^2*(sin(theta)^2)*(sin(phi)^2)+ $
a^2*b^2*(cos(phi)^2)))
RETURN, radius
end
pro dj_ellipsoid_ng, a, b, c, data=data
compile_opt idl2
;Create a grid of theta values
;These are the longitude of the of the
;ellipsoid and go from 0 to 360 degrees
theta_1d = (findgen(50)*360/50)*!DTOR
theta = CONGRID(TRANSPOSE(theta_1d),50,50)
theta = REFORM(TRANSPOSE(theta))
;Create a grid of phi values. These
;are the latitude of the ellipsoid and go
;from -90 to 90 degrees
phi_1d = ((findgen(50)-25)*180/50)*!DTOR
phi = congrid(TRANSPOSE(phi_1d),50,50)
;Use "get_rad" function to determine the
;radius values at each point of the theta
;and phi grid
radius = get_rad(theta,phi,a,b,c)
;Create a mesh using the radius values
;This outputs the vertices (vert) and polygons
;that will be used to generate the plot
mesh_obj,4,vert,pol,radius
;output the data
if (ARG_PRESENT(data)) then begin
data=vert
endif
;Determine the biggest value and create a scale from it
m = max([a,b,c])
scale = (findgen(10)-5)*m/5
;Plot the scale and axis with no data. Set CLIP=0, to
;prevent edges of ellipsoid from getting cut off.
p_scale =plot3d(scale,scale,scale,/NODATA,CLIP=0, ASPECT_Z=1, ASPECT_RATIO=1)
;Use the POLYGON to plot the mesh. Use the
;vertices and polygons output from the MESH_OBJ
;to fill out the DATA argument and CONNECTIVITY keyword.
;Use bright green as the color.
p = POLYGON(vert,CONNECTIVITY=pol,/data,CLIP=0,fill_color=[0,255,0])
end
;main level program
;For some reason, if 'a; does
;not equal 'b', the ellipsoid
;comes out messed up
dj_ellipsoid_ng,.75,.75,1,data=out_vert
end
Written by DS and reviewed by JU (03/11/2014)