Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ConeRep.cxx

Go to the documentation of this file.
00001 // $Heading: ConeRep.cxx $
00002 //   Author: T. Burnett
00003 
00004 #include "geomrep/ConeRep.h"
00005 
00006 #include "geometry/Cone.h"
00007 
00008 
00009 inline static void createPolyLine(gui::DisplayRep* v, Vector a[], unsigned n)
00010 {
00011     v->move_to(a[0]);
00012     for(unsigned i=1;i<n;i++)
00013         v->line_to(a[i]);
00014 }
00015 
00016 
00017 void ConeRep::update()
00018 {
00019         const int ns = 25;
00020         Vector vi0[25];   //  arrays for 24-sided polygons for drawing arcs
00021         Vector vo0[25];   //  need 1 set of x, y, z arrays for each end
00022         Vector vi1[25];   //  of inner (i) and outer (o) arcs of a Tube
00023         Vector vo1[25];
00024         Vector tv;
00025         
00026         int nonzero_inner_radius = m_cone.innerRadius(0)>0;
00027 
00028     //  calculate the coordinates of the inner and outer cylinders
00029         double hl = 0.5 * m_cone.length();
00030         double phi = 0.0;
00031         double dphi = 2.0 * M_PI / ( ns - 1 );
00032 
00033         Vector c = m_cone.center(),
00034                 axis = m_cone.axis(),
00035                c0 = c  -  hl * axis,
00036                c1 = c  +  hl * axis;
00037         Vector c0hat( 1.0, 0.0, 0.0 );
00038         float ax = axis.x();
00039         float ay = axis.y();
00040         float d = sqrt( ax * ax  +  ay * ay );
00041         if ( d > 0.0 )
00042                 c0hat = Vector( -ay/d, ax/d, 0.0 );
00043         Vector c1hat = axis.cross( c0hat );
00044         int i;
00045         for ( i = 0; i < ns; i++ ) {
00046                 phi = i * dphi;
00047                 tv = cos( phi ) * c0hat  +  sin( phi ) * c1hat;
00048                 vi0[i] = c0  +  m_cone.innerRadius(-hl) * tv;
00049                 vi1[i] = c1  +  m_cone.innerRadius(hl) * tv;
00050                 vo0[i] = c0  +  m_cone.outerRadius(-hl) * tv;
00051                 vo1[i] = c1  +  m_cone.outerRadius(hl) * tv;
00052         }
00053     //  draw inner cylinder (if inner radius is nonzero)
00054         if ( nonzero_inner_radius ) {
00055                 createPolyLine( this, vi0, ns );
00056                 createPolyLine( this, vi1, ns );
00057         }
00058     //  draw outer cylinder
00059         createPolyLine( this, vo0, ns );
00060         createPolyLine( this, vo1, ns );
00061    //  draw every third "rib" connecting the polygons
00062         for ( i = 0; i < ns; i += 3 ) {
00063                 Vector pl[] = { vo0[i], vo1[i], vi1[i], vi0[i], vo0[i] };
00064                 createPolyLine(this,  pl, 5 );
00065         }
00066 
00067 }
00068 

Generated at Mon Nov 26 18:18:45 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000