cgma
ParamCubitPlane.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : ParamCubitPlane.cc
00003 //
00004 // Purpose       : 
00005 //
00006 // Special Notes : 
00007 //
00008 // Creator       : Jason Kraftcheck
00009 //
00010 // Creation Date : 07/06/98
00011 //-------------------------------------------------------------------------
00012 
00013 #include "ParamCubitPlane.hpp"
00014 #include "CubitVector.hpp"
00015 #include "CubitMessage.hpp"
00016 #include "math.h"
00017 
00018 //-------------------------------------------------------------------------
00019 // Purpose       : Default constructor
00020 //
00021 // Special Notes : 
00022 //
00023 // Creator       : Jason Kraftcheck 
00024 //
00025 // Creation Date : 07/06/98
00026 //-------------------------------------------------------------------------
00027 ParamCubitPlane::ParamCubitPlane( const CubitVector& zero_position,
00028                                   const CubitVector& u_direction,
00029                                                                     const CubitVector& v_direction,
00030                                                                     CubitStatus& result )
00031 {
00032     if( mk_plane_with_points( zero_position, zero_position + u_direction, 
00033         zero_position + v_direction ) == (int)CUBIT_SUCCESS )
00034     {
00035         is_plane_valid_= CUBIT_TRUE;
00036         result = CUBIT_SUCCESS;
00037     }
00038     else
00039     {
00040         is_plane_valid_= CUBIT_FALSE;
00041         result = CUBIT_FAILURE;
00042         return ;
00043     }
00044     
00045     p_ = zero_position;
00046     s_ = u_direction;
00047     t_ = v_direction;
00048     n_ = s_ * t_;
00049     
00050     double n_len = n_.length();
00051     if( 1000 * CUBIT_DBL_MIN > n_len ) n_epsilon_ = CUBIT_DBL_MIN;
00052     else n_epsilon_ = n_len / 1000;
00053 }
00054 
00055 
00056 //-------------------------------------------------------------------------
00057 // Purpose       : closest point
00058 //
00059 // Special Notes : 
00060 //
00061 // Creator       : Jason Kraftcheck 
00062 //
00063 // Creation Date : 07/06/98
00064 //-------------------------------------------------------------------------
00065 CubitStatus ParamCubitPlane::closest_point( const CubitVector& position,
00066                              CubitVector& closest_position ) const
00067 {
00068     assert( is_plane_valid_);
00069     if( !is_plane_valid_) return CUBIT_FAILURE;
00070 
00071     closest_position = position - (normal() * distance(position));
00072     return CUBIT_SUCCESS;
00073 }
00074 
00075 //-------------------------------------------------------------------------
00076 // Purpose       : closest point
00077 //
00078 // Special Notes : 
00079 //
00080 // Creator       : Jason Kraftcheck 
00081 //
00082 // Creation Date : 07/06/98
00083 //-------------------------------------------------------------------------
00084 CubitStatus ParamCubitPlane::move_to_plane( CubitVector& position ) const
00085 {
00086     const CubitVector v = position;
00087     CubitStatus s = closest_point( v, position );
00088     return s;
00089 }       
00090 
00091 //-------------------------------------------------------------------------
00092 // Purpose       : make arbitrary parameterization
00093 //
00094 // Special Notes : 
00095 //
00096 // Creator       : Jason Kraftcheck 
00097 //
00098 // Creation Date : 07/06/98
00099 //-------------------------------------------------------------------------
00100 void ParamCubitPlane::make_parameterization()
00101 {
00102     //Choose the zero-point for the parameterization
00103     //as close to the origin as possible.
00104 //  p_.set( 0.0, 0.0, 0.0);
00105 //  move_to_plane( p_ );
00106     is_plane_valid_ = CUBIT_TRUE;
00107     
00108     const CubitVector temp_p(0.0, 0.0, 0.0);
00109     CubitStatus s = closest_point( temp_p, p_ );
00110     assert( s == CUBIT_SUCCESS );
00111     if (CUBIT_SUCCESS != s) {
00112       PRINT_ERROR("ParamCubitPlane::closest_point failed.\n");
00113       return;
00114     }
00115     
00116     CubitVector n = normal();
00117     CubitVector p1;
00118     
00119     p1 = p_;
00120     double x = fabs( n.x() );
00121     double y = fabs( n.y() );
00122     double z = fabs( n.z() );
00123     
00124     //Choose a direction from the zero point (p_) for
00125     //the second point as the direction of the smallest
00126     //component of the normal.  The third point defining
00127     //the plane will be defined by the cross product of
00128     //the vector from the zero_point to this point and
00129     //the normal vector of the plane.
00130     if( (x <= y) && (x <= z) )
00131     {
00132         p1.x( p1.x() + 1 );
00133     }
00134     else if( (y <= x) && (y <= z) )
00135     {
00136         p1.y( p1.y() + 1 );
00137     }
00138     else
00139     {
00140         p1.z( p1.z() + 1 );
00141     }
00142     
00143     move_to_plane( p1 );
00144     s_ = p1 - p_;
00145     t_ = -(s_ * n);
00146     n_ = s_ * t_;
00147     
00148     double n_len = n_.length();
00149     if( 1000 * CUBIT_DBL_MIN > n_len ) n_epsilon_ = CUBIT_DBL_MIN;
00150     else n_epsilon_ = n_len / 1000;
00151     
00152  
00153     is_plane_valid_= CUBIT_TRUE;
00154 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines