1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//-------------------------------------------------------------------------<--- Skipping configuration 'DBL_MAX' since the value of 'DBL_MAX' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'DBL_MIN' since the value of 'DBL_MIN' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'M_PI' since the value of 'M_PI' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.
// Filename      : ParamCubitPlane.cc
//
// Purpose       : 
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------

#include "ParamCubitPlane.hpp"
#include "CubitVector.hpp"
#include "CubitMessage.hpp"
#include "math.h"

//-------------------------------------------------------------------------
// Purpose       : Default constructor
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck 
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------
ParamCubitPlane::ParamCubitPlane( const CubitVector& zero_position,
                                  const CubitVector& u_direction,
																	const CubitVector& v_direction,
																	CubitStatus& result )
{
	if( mk_plane_with_points( zero_position, zero_position + u_direction, 
	    zero_position + v_direction ) == (int)CUBIT_SUCCESS )
	{
		is_plane_valid_= CUBIT_TRUE;
		result = CUBIT_SUCCESS;
	}
	else
	{
		is_plane_valid_= CUBIT_FALSE;
		result = CUBIT_FAILURE;
		return ;
	}
	
	p_ = zero_position;
	s_ = u_direction;
	t_ = v_direction;
	n_ = s_ * t_;
	
	double n_len = n_.length();
	if( 1000 * CUBIT_DBL_MIN > n_len ) n_epsilon_ = CUBIT_DBL_MIN;
	else n_epsilon_ = n_len / 1000;
}


//-------------------------------------------------------------------------
// Purpose       : closest point
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck 
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------
CubitStatus ParamCubitPlane::closest_point( const CubitVector& position,
                             CubitVector& closest_position ) const
{
	assert( is_plane_valid_);
	if( !is_plane_valid_) return CUBIT_FAILURE;

	closest_position = position - (normal() * distance(position));
	return CUBIT_SUCCESS;
}

//-------------------------------------------------------------------------
// Purpose       : closest point
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck 
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------
CubitStatus ParamCubitPlane::move_to_plane( CubitVector& position ) const
{
	const CubitVector v = position;
	CubitStatus s = closest_point( v, position );
	return s;
}		

//-------------------------------------------------------------------------
// Purpose       : make arbitrary parameterization
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck 
//
// Creation Date : 07/06/98
//-------------------------------------------------------------------------
void ParamCubitPlane::make_parameterization()<--- The function 'make_parameterization' is never used.
{
	//Choose the zero-point for the parameterization
	//as close to the origin as possible.
//	p_.set( 0.0, 0.0, 0.0);
//	move_to_plane( p_ );
	is_plane_valid_ = CUBIT_TRUE;
	
	const CubitVector temp_p(0.0, 0.0, 0.0);
	CubitStatus s = closest_point( temp_p, p_ );
	assert( s == CUBIT_SUCCESS );
	if (CUBIT_SUCCESS != s) {
	  PRINT_ERROR("ParamCubitPlane::closest_point failed.\n");
	  return;
	}
	
	CubitVector n = normal();
	CubitVector p1;
	
	p1 = p_;
	double x = fabs( n.x() );
	double y = fabs( n.y() );
	double z = fabs( n.z() );
	
	//Choose a direction from the zero point (p_) for
	//the second point as the direction of the smallest
	//component of the normal.  The third point defining
	//the plane will be defined by the cross product of
	//the vector from the zero_point to this point and
	//the normal vector of the plane.
	if( (x <= y) && (x <= z) )
	{
		p1.x( p1.x() + 1 );
	}
	else if( (y <= x) && (y <= z) )
	{
		p1.y( p1.y() + 1 );
	}
	else
	{
		p1.z( p1.z() + 1 );
	}
	
	move_to_plane( p1 );
	s_ = p1 - p_;
	t_ = -(s_ * n);
	n_ = s_ * t_;
	
	double n_len = n_.length();
	if( 1000 * CUBIT_DBL_MIN > n_len ) n_epsilon_ = CUBIT_DBL_MIN;
	else n_epsilon_ = n_len / 1000;
	
 
 	is_plane_valid_= CUBIT_TRUE;
}