// // $Id: RegularPolygonSurface.cpp,v 1.6 2002/08/25 20:24:27 melanson Exp $ // // File: RegularPolygonSurface.cpp // Purpose: // Created: 26-APR-1999 // // $Revision: 1.6 $ // // // Include files #include #include #include #include #include #include static const double PI=3.1415927; using namespace std; using namespace dgs; SpacePoint RegularPolygonSurface::local_to_global( const CartesianCoordinate& lpt) const // // Purpose: // { return GeometryElement::local_to_global(lpt); } MatrixD RegularPolygonSurface::local_to_global( const CartesianMatrix& theMatrix) const // // Purpose: // { return GeometryElement::local_to_global(theMatrix); } CartesianCoordinate RegularPolygonSurface::global_to_local( const SpacePoint& gpt) const // // Purpose: Convert a global point to its local point representation // States: // { CartesianCoordinate undone = get_position().invert(gpt); if( undone.z() != 0.0 ) cerr << "RegularPolygonSurface::local_to_global. Local coordinate" << " has non-zero z-component" << endl; return undone; } CartesianCoordinate RegularPolygonSurface::xform_to_local( const GeometryXform& xf) const // // Purpose: Convert a (local)transform to local coordinates. Lose the // rotation information because one can position children only in // the plane of the polygon. This is described by an (x,y) pair. // { CartesianCoordinate xlpt(xf[0],xf[1],0.0); if( !point_ok(xlpt) ) { ostringstream message; message << "RegularPolygonSurface, Point: (x,y) = (" << xlpt.x() << "," << xlpt.y() << ")"; throw XGSIllegalPoint(message.str().c_str()); } return xlpt; } GeometryXform RegularPolygonSurface::local_to_xform( const CartesianCoordinate& lpt) const // // Purpose: Create a transformation describing a point on my surface. // { if( !point_ok(lpt) ) throw XGSIllegalPoint(""); return GeometryXform(lpt.x(),lpt.y(),0.0,0.0,0.0,0.0); } bool RegularPolygonSurface::position_child_at(const CartesianCoordinate& lpt, GeometryElement& kid) // // Purpose: // States: // { GeometryXform gxf = local_to_xform(lpt); gxf = get_position().apply(gxf); kid.set_position(gxf); return true; } bool RegularPolygonSurface::resize(const double dlin, const double dlout) // // Purpose: // { d_lenin += dlin; d_lenout += dlout; return true; } double RegularPolygonSurface::get_inner_radius() const // // Purpose: Return the radius of a circle inscribed inside the inner edge // -1.0 is returned as an error condition // { if( d_ns<3 ) return -1.0; // Throw an exception? return d_lenin/(2*tan(PI/d_ns)); // return d_ns*d_lenin/(2*PI*tan(PI/d_ns)); } double RegularPolygonSurface::get_outer_radius() const // // Purpose: Return the radius of a circle inscribed inside the outer edge // -1.0 is returned as an error condition { if( d_ns<3 ) return -1.0; // Throw an exception? return d_lenout/(2*tan(PI/d_ns)); //return d_ns*d_lenout/(2*PI*tan(PI/d_ns)); } bool RegularPolygonSurface::point_ok(const CartesianCoordinate& lpt) const { double dphi = 2*PI/d_ns; double phi0 = -dphi/2.0; // Need this 'cause phi=0 is center of a side double iside = 0; // Actually takes on integer values... while( (iside*dphi-phi0)