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

Cone.cxx

Go to the documentation of this file.
00001 // $Id: Cone.cxx,v 1.4 2001/04/17 01:47:41 burnett Exp $
00002 //
00003 
00004 
00005 #include "geometry/Cone.h"
00006 
00007 #include "geometry/Conic.h"
00008 #include "geometry/Plane.h"
00009 #include <algorithm>
00010 #include <cmath>
00011 inline static double sqr(double x){return x*x;}
00012 
00013 static Vector zhat(0,0,1);
00014 
00015 Cone::Cone( double length, double ri1, double ro1, double ri2, double ro2 )
00016 : Volume( ((ri1 > 0) && (ri2 >0))? 4:3)
00017 {
00018   //  Make a Cone with length z, inner radius ri1 and outer radius ro1 at the
00019   //  -z end, and inner radius ri2, and outer radius ro2 at the +z end.
00020   //  Note that the following relations must hold for a valid Cone:
00021   //  z > 0, ri2 > ri1 >= 0, ro2 > ro1 > ri1, and ro2 > ri2.
00022    if ( ( length <= 0.0 ) || ( ri1 <  0.0 ) || ( ro1 <= ri1 )
00023                           || ( ri2 <  0.0 ) || ( ro2 <= ri2 )
00024       )FATAL("Illegal parameters for Cone");
00025 
00026    double h_z = 0.5*length;
00027    addSurface(new Conic( center(), zhat, 0.5*(ro1 +ro2), (ro2-ro1)/length) );
00028 
00029    addSurface(new Plane(center(),  h_z*zhat) );
00030    addSurface(new Plane(center(), -h_z*zhat) );
00031 
00032    if( ri1 > 0 && ri2 >0 ) // add inner surface if not solid
00033           addSurface(new Conic( center(), zhat, -0.5*(ri1 +ri2), -(ri2-ri1)/length));
00034 
00035    max_dimension =  sqrt( sqr(length) + sqr(std::max(ro1,ro2)));
00036 
00037 }
00038 
00039 // This assumes order of surfaces set by code just above. Beware!
00040 double Cone::outerRadius(double z)const
00041 {
00042     return  ((Conic&)surface(0)).radius(z);
00043 }
00044 double Cone::innerRadius(double z)const
00045 {
00046     return surfaceCount()>3? -((Conic&)surface(3)).radius(z): 0 ;
00047 }
00048 
00049 
00050 double Cone::length()const
00051 {
00052    return 2*((Plane&)surface(1)).offset();
00053 }
00054 Vector Cone::axis()const{return ((Conic&)surface(0)).axis();}
00055 
00056 void Cone::printOn( std::ostream& os ) const
00057 {
00058    double h = 0.5*length();
00059    Volume::printOn(os);
00060         os  << "  length " << length()
00061             << ", inner radii: " << innerRadius(-h)<< ", " << innerRadius(+h)
00062             << ", outer radii: " << outerRadius(-h)<< ", " << outerRadius(+h)
00063             << "\n" ;
00064 }
00065 
00066 

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