cgma
SphereEvaluator.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : FacetSurface.cpp
00003 //
00004 // Purpose       : 
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : David R. White
00009 //
00010 // Creation Date : 06/06/00
00011 //
00012 // Owner         : David R. White
00013 //-------------------------------------------------------------------------
00014 
00015 #include "SphereEvaluator.hpp"
00016 #include "CubitMessage.hpp"
00017 #include "CubitBox.hpp"
00018 #include "CubitVector.hpp"
00019 
00020 // ********** END CUBIT INCLUDES           **********
00021 
00022 // ********** BEGIN STATIC DECLARATIONS    **********
00023 // ********** END STATIC DECLARATIONS      **********
00024 
00025 // ********** BEGIN PUBLIC FUNCTIONS       **********
00026 
00027 //-------------------------------------------------------------------------
00028 // Purpose       : Compute and return the bounding box for this sphere.
00029 //
00030 // Special Notes :
00031 //
00032 //-------------------------------------------------------------------------
00033 CubitBox SphereEvaluator::bounding_box( void ) const
00034 {
00035     CubitVector center = mTmatrix * mEvalData.center;
00036             
00037     CubitVector min( center.x() - mEvalData.radius,
00038                      center.y() - mEvalData.radius,
00039                      center.z() - mEvalData.radius );
00040     CubitVector max( center.x() + mEvalData.radius,
00041                      center.y() + mEvalData.radius,
00042                      center.z() + mEvalData.radius );
00043 
00044     CubitBox thebbox( min, max );
00045 
00046     return thebbox;
00047 }
00048 
00049 //-------------------------------------------------------------------------
00050 // Purpose       : This functions computes the point on the surface that is 
00051 //                 closest to the input location and then calculates the 
00052 //                 magnitudes of the principal curvatures at this (possibly, 
00053 //                 new) point on the surface.
00054 //
00055 // Special Notes :
00056 //
00057 //-------------------------------------------------------------------------
00058 CubitStatus SphereEvaluator::principal_curvatures(
00059   CubitVector const& location,
00060   double& curvature_1,
00061   double& curvature_2,
00062   CubitVector* closest_location )
00063 {
00064 
00065     curvature_1 = curvature_2 = 1.0 / mEvalData.radius;
00066 
00067     if ( closest_location )
00068     {
00069         closest_point( location, closest_location );
00070     }
00071     return CUBIT_SUCCESS;
00072 }
00073 
00074 //-------------------------------------------------------------------------
00075 // Purpose       : Computes the closest_point on the surface to the input 
00076 //                 location.  Optionally, it also computes and returns
00077 //                 the normal to the surface and the principal curvatures
00078 //                 at closest_location.
00079 //
00080 //-------------------------------------------------------------------------
00081 CubitStatus SphereEvaluator::closest_point( CubitVector const& location, 
00082                                             CubitVector* closest_location,
00083                                             CubitVector* unit_normal_ptr,
00084                                             CubitVector* curvature1_ptr,
00085                                             CubitVector* curvature2_ptr) const
00086 {
00087     CubitTransformMatrix inverse_Tmatrix = mTmatrix;
00088     inverse_Tmatrix.inverse();
00089     CubitVector new_pt = inverse_Tmatrix * location;
00090 
00091     // ******************************************************
00092     // If requested, compute the normal at the input point.
00093     // ******************************************************
00094 
00095     if ( unit_normal_ptr != NULL )
00096     {
00097         CubitVector origin( 0.0, 0.0, 0.0 );
00098         CubitVector endpt = new_pt - mEvalData.center;
00099 
00100         origin = mTmatrix * origin;
00101         endpt  = mTmatrix * endpt;
00102 
00103         *unit_normal_ptr = endpt - origin;
00104         unit_normal_ptr->normalize();
00105     }
00106 
00107     // *************************************************************
00108     // If requested, compute the closest point to the input point.
00109     // *************************************************************
00110 
00111     if ( closest_location != NULL )
00112     {
00113         if ( location.within_tolerance( mEvalData.center, GEOMETRY_RESABS ) )
00114         {
00115             closest_location->set( mEvalData.center.x() + mEvalData.radius,
00116                                    mEvalData.center.y(),
00117                                    mEvalData.center.z() );
00118         }
00119         else
00120         {
00121             CubitVector vec = new_pt - mEvalData.center;
00122             vec.normalize();
00123             *closest_location = mEvalData.center + ( vec * mEvalData.radius );
00124             *closest_location = mTmatrix * (*closest_location);
00125         }
00126     }
00127 
00128     // ***********************************************************************
00129     // If requested, compute the curvature directions.
00130     // ***********************************************************************
00131 
00132     if ( curvature1_ptr &&
00133          curvature2_ptr )
00134     {
00135         PRINT_ERROR("Sphere's do not current support curvature pointer requests.\n");
00136         return CUBIT_FAILURE;
00137     }
00138   
00139     return CUBIT_SUCCESS;
00140 }
00141 
00142 //-------------------------------------------------------------------------
00143 // Purpose       : Given a UV parametric location, return the cooresponding
00144 //                 XYZ location.
00145 //-------------------------------------------------------------------------
00146 CubitVector SphereEvaluator::position_from_u_v( double u, double v ) const
00147 {
00148     double two_pi = 2.0 * CUBIT_PI;
00149 
00150     while ( u > two_pi ) u -= two_pi;
00151     while ( u < 0.0    ) u += two_pi;
00152 
00153     double radius_modified = mEvalData.radius * sin ( v );
00154     double x = radius_modified * cos( u );
00155     double y = radius_modified * sin( u );
00156     double z = mEvalData.radius * cos( v );
00157 
00158     CubitVector position( x, y, z );
00159     position = mTmatrix * position;
00160 
00161     return position;
00162 }
00163 
00164 //-------------------------------------------------------------------------
00165 // Purpose       : Project a given XYZ position to a surface and return
00166 //                 the UV and XYZ locations on the surface.
00167 //-------------------------------------------------------------------------
00168 CubitStatus SphereEvaluator::u_v_from_position
00169 (
00170     CubitVector const& location,
00171     double& u,
00172     double& v,
00173     CubitVector* closest_location
00174 ) const
00175 {
00176     CubitTransformMatrix inverse_Tmatrix = mTmatrix;
00177     inverse_Tmatrix.inverse();
00178     CubitVector transformed_pt = inverse_Tmatrix * location;
00179 
00180     CubitVector dir( transformed_pt );
00181     dir.normalize();
00182 
00183     v = acos( dir.z() );
00184 
00185     if ( v < GEOMETRY_RESABS )
00186     {
00187         u = 0.0;
00188     }
00189     else
00190     {
00191         dir.set( dir.x(), dir.y(), 0.0 );
00192         dir.normalize();
00193         u = acos( dir.x() );
00194 
00195         if ( dir.y() < 0.0 )
00196         {
00197             u = 2*CUBIT_PI - u;
00198         }
00199         while ( u < 0.0 ) u += 2*CUBIT_PI;
00200         while ( u >= 2*CUBIT_PI ) u -= 2*CUBIT_PI;
00201     }
00202 
00203     if ( closest_location )
00204         closest_point( location, closest_location );
00205     return CUBIT_SUCCESS;
00206 }
00207 
00208 //-------------------------------------------------------------------------
00209 // Purpose       : returns a structure containing the parameters for this
00210 //                 sphere (i.e. radius, center, etc.)
00211 //
00212 //-------------------------------------------------------------------------
00213 const CubitEvaluatorData* SphereEvaluator::evaluator_data( void ) const
00214 {
00215     return &mEvalData;
00216 }
00217 
00218 //-------------------------------------------------------------------------
00219 // Purpose       : return parametric extremes in the U direction
00220 //
00221 //-------------------------------------------------------------------------
00222 CubitBoolean SphereEvaluator::get_param_range_U
00223 (
00224     double& lower_bound,
00225     double& upper_bound
00226 ) const
00227 {
00228    lower_bound = 0.0;
00229    upper_bound = 2.0*CUBIT_PI;
00230    return CUBIT_TRUE;
00231 }
00232 
00233 //-------------------------------------------------------------------------
00234 // Purpose       : return parametric extremes in the V direction
00235 //
00236 //-------------------------------------------------------------------------
00237 CubitBoolean SphereEvaluator::get_param_range_V
00238 (
00239     double& lower_bound,
00240     double& upper_bound
00241 ) const
00242 {
00243    lower_bound = 0;
00244    upper_bound = CUBIT_PI;
00245    return CUBIT_TRUE;
00246 }
00247 
00248 // ********** END PUBLIC FUNCTIONS         **********
00249 
00250 // ********** BEGIN PROTECTED FUNCTIONS    **********
00251 // ********** END PROTECTED FUNCTIONS      **********
00252 
00253 // ********** BEGIN PRIVATE FUNCTIONS      **********
00254 // ********** END PRIVATE FUNCTIONS        **********
00255 
00256 // ********** BEGIN HELPER CLASSES         **********
00257 // ********** END HELPER CLASSES           **********
00258 
00259 // ********** BEGIN EXTERN FUNCTIONS       **********
00260 // ********** END EXTERN FUNCTIONS         **********
00261 
00262 // ********** BEGIN STATIC FUNCTIONS       **********
00263 // ********** END STATIC FUNCTIONS         **********
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines