X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



5753 Rate this article:
No rating

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)

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »