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

Tube.cxx

Go to the documentation of this file.
00001 // $Id: Tube.cxx,v 1.3 2000/12/14 23:18:11 burnett Exp $
00002 //
00003 
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #include "config.h"
00007 #endif
00008 
00009 #include "geometry/Tube.h"
00010 
00011 #include "geometry/Cylinder.h"
00012 #include "geometry/Plane.h"
00013 
00014 inline static double sqr(double x){return x*x;}
00015 
00016 static Vector zhat(0,0,1);
00017 
00018 Tube::Tube( double length, double innerRadius, double outerRadius )
00019 : Volume( (innerRadius>0)? 4 : 3)
00020 {
00021     calculateSurfaces(length, innerRadius, outerRadius);
00022 }
00023 
00024 void Tube::resize( double length, double innerRadius, double outerRadius )
00025 {
00026     deleteSurfaces();
00027     calculateSurfaces(length, innerRadius, outerRadius);
00028 }
00029 
00030 
00031 void Tube::calculateSurfaces( double length, double innerRadius, double outerRadius )
00032 {
00033    if(    innerRadius<0 || innerRadius>outerRadius
00034        || outerRadius<0 || length <=0
00035       )FATAL("Illegal parameters for Tube::calculateSurfaces");
00036 
00037     // don't reorder these without looking below!
00038         addSurface(new Cylinder(center(),  outerRadius));
00039     addSurface(new Plane(center(), 0.5*length*zhat));
00040     addSurface(new Plane(center(),-0.5*length*zhat));
00041     if( innerRadius !=0)
00042         addSurface(new Cylinder(center(), -innerRadius));  // must be last!     
00043         
00044     max_dimension =  sqrt( sqr(length) + sqr(outerRadius));
00045 }
00046 // These assume order of surfaces set by code just above. Beware!
00047 
00048 double Tube::outerRadius()const{ return ((Cylinder&)surface(0)).radius();}
00049 
00050 double Tube::innerRadius()const{
00051     return surfaceCount()>3? -((Cylinder&)surface(3)).radius(): 0 ;}
00052 
00053 double Tube::length()const
00054 {  return  2* ((Plane&)surface(1)).offset();
00055 }
00056 const Vector& Tube::axis()const{return ((Cylinder&)surface(0)).axis();}
00057 
00058 
00059 
00060 void Tube::printOn( std::ostream& os ) const
00061 {  //  printing function, uses C++ ostream class object
00062         Volume::printOn(os);
00063         os  << "  length " << length()
00064             << ", inner, outer radii: "
00065             << innerRadius()<< ", " << outerRadius() << "\n" ;
00066 }
00067 
00068 
00069 
00070 
00071 

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