Point Cloud Library (PCL)
1.7.0
|
00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00014 //////////////////////////////////////////////////////////////// 00015 */ 00016 00017 //////////////////////////////////////////////////////////////// 00018 // 00019 // defines float precision point, vector, and array classes 00020 // 00021 //////////////////////////////////////////////////////////////// 00022 #if !defined(ON_FPOINT_INC_) 00023 #define ON_FPOINT_INC_ 00024 00025 class ON_Xform; 00026 00027 class ON_2fPoint; 00028 class ON_3fPoint; 00029 class ON_4fPoint; 00030 00031 class ON_2fVector; 00032 class ON_3fVector; 00033 00034 //////////////////////////////////////////////////////////////// 00035 // 00036 // ON_2fPoint 00037 // 00038 class ON_CLASS ON_2fPoint 00039 { 00040 public: 00041 float x, y; 00042 00043 static const ON_2fPoint Origin; // (0.0f,0.0f) 00044 00045 // use implicit destructor, copy constructor 00046 ON_2fPoint(); // x,y not initialized 00047 ON_2fPoint(float x,float y); 00048 00049 ON_2fPoint(const ON_3fPoint& ); // from 3f point 00050 ON_2fPoint(const ON_4fPoint& ); // from 4f point 00051 ON_2fPoint(const ON_2fVector& ); // from 2f vector 00052 ON_2fPoint(const ON_3fVector& ); // from 3f vector 00053 ON_2fPoint(const float*); // from float[2] array 00054 00055 ON_2fPoint(const ON_2dPoint& ); // from 2d point 00056 ON_2fPoint(const ON_3dPoint& ); // from 3d point 00057 ON_2fPoint(const ON_4dPoint& ); // from 4d point 00058 ON_2fPoint(const ON_2dVector& ); // from 2d vector 00059 ON_2fPoint(const ON_3dVector& ); // from 3d vector 00060 ON_2fPoint(const double*); // from double[2] array 00061 00062 // (float*) conversion operators 00063 operator float*(); 00064 operator const float*() const; 00065 00066 // use implicit operator=(const ON_2fPoint&) 00067 ON_2fPoint& operator=(const ON_3fPoint&); 00068 ON_2fPoint& operator=(const ON_4fPoint&); 00069 ON_2fPoint& operator=(const ON_2fVector&); 00070 ON_2fPoint& operator=(const ON_3fVector&); 00071 ON_2fPoint& operator=(const float*); // point = float[2] support 00072 00073 ON_2fPoint& operator=(const ON_2dPoint&); 00074 ON_2fPoint& operator=(const ON_3dPoint&); 00075 ON_2fPoint& operator=(const ON_4dPoint&); 00076 ON_2fPoint& operator=(const ON_2dVector&); 00077 ON_2fPoint& operator=(const ON_3dVector&); 00078 ON_2fPoint& operator=(const double*); // point = double[2] support 00079 00080 ON_2fPoint& operator*=(float); 00081 ON_2fPoint& operator/=(float); 00082 ON_2fPoint& operator+=(const ON_2fPoint&); 00083 ON_2fPoint& operator+=(const ON_2fVector&); 00084 ON_2fPoint& operator+=(const ON_3fVector&); 00085 ON_2fPoint& operator-=(const ON_2fPoint&); 00086 ON_2fPoint& operator-=(const ON_2fVector&); 00087 ON_2fPoint& operator-=(const ON_3fVector&); 00088 00089 ON_2fPoint operator*(int) const; 00090 ON_2fPoint operator/(int) const; 00091 ON_2fPoint operator*(float) const; 00092 ON_2fPoint operator/(float) const; 00093 ON_2dPoint operator*(double) const; 00094 ON_2dPoint operator/(double) const; 00095 00096 ON_2fPoint operator+(const ON_2fPoint&) const; 00097 ON_2fPoint operator+(const ON_2fVector&) const; 00098 ON_2fVector operator-(const ON_2fPoint&) const; 00099 ON_2fPoint operator-(const ON_2fVector&) const; 00100 ON_3fPoint operator+(const ON_3fPoint&) const; 00101 ON_3fPoint operator+(const ON_3fVector&) const; 00102 ON_3fVector operator-(const ON_3fPoint&) const; 00103 ON_3fPoint operator-(const ON_3fVector&) const; 00104 00105 ON_2dPoint operator+(const ON_2dPoint&) const; 00106 ON_2dPoint operator+(const ON_2dVector&) const; 00107 ON_2dVector operator-(const ON_2dPoint&) const; 00108 ON_2dPoint operator-(const ON_2dVector&) const; 00109 ON_3dPoint operator+(const ON_3dPoint&) const; 00110 ON_3dPoint operator+(const ON_3dVector&) const; 00111 ON_3dVector operator-(const ON_3dPoint&) const; 00112 ON_3dPoint operator-(const ON_3dVector&) const; 00113 00114 float operator*(const ON_2fPoint&) const; // for points acting as vectors 00115 float operator*(const ON_2fVector&) const; // for points acting as vectors 00116 float operator*(const ON_4fPoint&) const; 00117 00118 bool operator==(const ON_2fPoint&) const; 00119 bool operator!=(const ON_2fPoint&) const; 00120 00121 // dictionary order comparisons 00122 bool operator<=(const ON_2fPoint&) const; 00123 bool operator>=(const ON_2fPoint&) const; 00124 bool operator<(const ON_2fPoint&) const; 00125 bool operator>(const ON_2fPoint&) const; 00126 00127 // index operators mimic float[2] behavior 00128 float& operator[](int); 00129 float operator[](int) const; 00130 float& operator[](unsigned int); 00131 float operator[](unsigned int) const; 00132 00133 // set 2d point value 00134 void Set(float,float); 00135 00136 double DistanceTo( const ON_2fPoint& ) const; 00137 00138 int MaximumCoordinateIndex() const; 00139 double MaximumCoordinate() const; // absolute value of maximum coordinate 00140 00141 void Zero(); // set all coordinates to zero; 00142 00143 // These transform the point in place. The transformation matrix acts on 00144 // the left of the point; i.e., result = transformation*point 00145 void Transform( 00146 const ON_Xform& 00147 ); 00148 00149 void Rotate( // rotatation in XY plane 00150 double, // angle in radians 00151 const ON_2fPoint& // center of rotation 00152 ); 00153 00154 void Rotate( // rotatation in XY plane 00155 double, // sin(angle) 00156 double, // cos(angle) 00157 const ON_2fPoint& // center of rotation 00158 ); 00159 }; 00160 00161 ON_DECL 00162 ON_2fPoint operator*(int, const ON_2fPoint&); 00163 00164 ON_DECL 00165 ON_2fPoint operator*(float, const ON_2fPoint&); 00166 00167 ON_DECL 00168 ON_2dPoint operator*(double, const ON_2fPoint&); 00169 00170 //////////////////////////////////////////////////////////////// 00171 // 00172 // ON_3fPoint 00173 // 00174 class ON_CLASS ON_3fPoint 00175 { 00176 public: 00177 float x, y, z; 00178 00179 static const ON_3fPoint Origin; // (0.0f,0.0f,0.0f) 00180 00181 // use implicit destructor, copy constructor 00182 ON_3fPoint(); // x,y,z not initialized 00183 ON_3fPoint(float x,float y,float z); 00184 ON_3fPoint(const ON_2fPoint& ); // from 2f point 00185 ON_3fPoint(const ON_4fPoint& ); // from 4f point 00186 ON_3fPoint(const ON_2fVector& ); // from 2f vector 00187 ON_3fPoint(const ON_3fVector& ); // from 3f vector 00188 ON_3fPoint(const float*); // from float[3] array 00189 00190 ON_3fPoint(const ON_2dPoint& ); // from 2d point 00191 ON_3fPoint(const ON_3dPoint& ); // from 3d point 00192 ON_3fPoint(const ON_4dPoint& ); // from 4d point 00193 ON_3fPoint(const ON_2dVector& ); // from 2d vector 00194 ON_3fPoint(const ON_3dVector& ); // from 3d vector 00195 ON_3fPoint(const double*); // from double[3] array 00196 00197 // (float*) conversion operators 00198 operator float*(); 00199 operator const float*() const; 00200 00201 // use implicit operator=(const ON_3fPoint&) 00202 ON_3fPoint& operator=(const ON_2fPoint&); 00203 ON_3fPoint& operator=(const ON_4fPoint&); 00204 ON_3fPoint& operator=(const ON_2fVector&); 00205 ON_3fPoint& operator=(const ON_3fVector&); 00206 ON_3fPoint& operator=(const float*); // point = float[3] support 00207 00208 ON_3fPoint& operator=(const ON_2dPoint&); 00209 ON_3fPoint& operator=(const ON_3dPoint&); 00210 ON_3fPoint& operator=(const ON_4dPoint&); 00211 ON_3fPoint& operator=(const ON_2dVector&); 00212 ON_3fPoint& operator=(const ON_3dVector&); 00213 ON_3fPoint& operator=(const double*); // point = double[3] support 00214 00215 ON_3fPoint& operator*=(float); 00216 ON_3fPoint& operator/=(float); 00217 ON_3fPoint& operator+=(const ON_3fPoint&); 00218 ON_3fPoint& operator+=(const ON_3fVector&); 00219 ON_3fPoint& operator-=(const ON_3fPoint&); 00220 ON_3fPoint& operator-=(const ON_3fVector&); 00221 00222 ON_3fPoint operator*(int) const; 00223 ON_3fPoint operator/(int) const; 00224 ON_3fPoint operator*(float) const; 00225 ON_3fPoint operator/(float) const; 00226 ON_3dPoint operator*(double) const; 00227 ON_3dPoint operator/(double) const; 00228 00229 ON_3fPoint operator+(const ON_3fPoint&) const; 00230 ON_3fPoint operator+(const ON_3fVector&) const; 00231 ON_3fVector operator-(const ON_3fPoint&) const; 00232 ON_3fPoint operator-(const ON_3fVector&) const; 00233 ON_3fPoint operator+(const ON_2fPoint&) const; 00234 ON_3fPoint operator+(const ON_2fVector&) const; 00235 ON_3fVector operator-(const ON_2fPoint&) const; 00236 ON_3fPoint operator-(const ON_2fVector&) const; 00237 00238 ON_3dPoint operator+(const ON_3dPoint&) const; 00239 ON_3dPoint operator+(const ON_3dVector&) const; 00240 ON_3dVector operator-(const ON_3dPoint&) const; 00241 ON_3dPoint operator-(const ON_3dVector&) const; 00242 ON_3dPoint operator+(const ON_2dPoint&) const; 00243 ON_3dPoint operator+(const ON_2dVector&) const; 00244 ON_3dVector operator-(const ON_2dPoint&) const; 00245 ON_3dPoint operator-(const ON_2dVector&) const; 00246 00247 float operator*(const ON_3fPoint&) const; // for points acting as vectors 00248 float operator*(const ON_3fVector&) const; // for points acting as vectors 00249 float operator*(const ON_4fPoint&) const; 00250 00251 bool operator==(const ON_3fPoint&) const; 00252 bool operator!=(const ON_3fPoint&) const; 00253 00254 // dictionary order comparisons 00255 bool operator<=(const ON_3fPoint&) const; 00256 bool operator>=(const ON_3fPoint&) const; 00257 bool operator<(const ON_3fPoint&) const; 00258 bool operator>(const ON_3fPoint&) const; 00259 00260 // index operators mimic float[3] behavior 00261 float& operator[](int); 00262 float operator[](int) const; 00263 float& operator[](unsigned int); 00264 float operator[](unsigned int) const; 00265 00266 // set 3d point value 00267 void Set(float,float,float); 00268 00269 double DistanceTo( const ON_3fPoint& ) const; 00270 00271 int MaximumCoordinateIndex() const; 00272 double MaximumCoordinate() const; // absolute value of maximum coordinate 00273 double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d points 00274 00275 void Zero(); // set all coordinates to zero; 00276 00277 // These transform the point in place. The transformation matrix acts on 00278 // the left of the point; i.e., result = transformation*point 00279 void Transform( 00280 const ON_Xform& 00281 ); 00282 00283 void Rotate( 00284 double, // angle in radians 00285 const ON_3fVector&, // axis of rotation 00286 const ON_3fPoint& // center of rotation 00287 ); 00288 00289 void Rotate( 00290 double, // sin(angle) 00291 double, // cos(angle) 00292 const ON_3fVector&, // axis of rotation 00293 const ON_3fPoint& // center of rotation 00294 ); 00295 }; 00296 00297 ON_DECL 00298 ON_3fPoint operator*(int, const ON_3fPoint&); 00299 00300 ON_DECL 00301 ON_3fPoint operator*(float, const ON_3fPoint&); 00302 00303 ON_DECL 00304 ON_3dPoint operator*(double, const ON_3fPoint&); 00305 00306 //////////////////////////////////////////////////////////////// 00307 // 00308 // ON_4fPoint (homogeneous coordinates) 00309 // 00310 class ON_CLASS ON_4fPoint 00311 { 00312 public: 00313 float x, y, z, w; 00314 00315 // use implicit destructor, copy constructor 00316 ON_4fPoint(); // x,y,z,w not initialized 00317 ON_4fPoint(float x,float y,float z,float w); 00318 00319 ON_4fPoint(const ON_2fPoint& ); // from 2f point 00320 ON_4fPoint(const ON_3fPoint& ); // from 3f point 00321 ON_4fPoint(const ON_2fVector& ); // from 2f vector 00322 ON_4fPoint(const ON_3fVector& ); // from 3f vector 00323 ON_4fPoint(const float*); // from float[4] array 00324 00325 ON_4fPoint(const ON_2dPoint& ); // from 2d point 00326 ON_4fPoint(const ON_3dPoint& ); // from 3d point 00327 ON_4fPoint(const ON_4dPoint& ); // from 4d point 00328 ON_4fPoint(const ON_2dVector& ); // from 2d vector 00329 ON_4fPoint(const ON_3dVector& ); // from 3d vector 00330 ON_4fPoint(const double*); // from double[4] array 00331 00332 // (float*) conversion operators 00333 operator float*(); 00334 operator const float*() const; 00335 00336 // use implicit operator=(const ON_4fPoint&) 00337 ON_4fPoint& operator=(const ON_2fPoint&); 00338 ON_4fPoint& operator=(const ON_3fPoint&); 00339 ON_4fPoint& operator=(const ON_2fVector&); 00340 ON_4fPoint& operator=(const ON_3fVector&); 00341 ON_4fPoint& operator=(const float*); // point = float[4] support 00342 00343 ON_4fPoint& operator=(const ON_2dPoint&); 00344 ON_4fPoint& operator=(const ON_3dPoint&); 00345 ON_4fPoint& operator=(const ON_4dPoint&); 00346 ON_4fPoint& operator=(const ON_2dVector&); 00347 ON_4fPoint& operator=(const ON_3dVector&); 00348 ON_4fPoint& operator=(const double*); // point = double[4] support 00349 00350 ON_4fPoint& operator*=(float); 00351 ON_4fPoint& operator/=(float); 00352 ON_4fPoint& operator+=(const ON_4fPoint&); 00353 ON_4fPoint& operator-=(const ON_4fPoint&); 00354 00355 ON_4fPoint operator*(float) const; 00356 ON_4fPoint operator/(float) const; 00357 ON_4fPoint operator+(const ON_4fPoint&) const; // sum w = sqrt(w1*w2) 00358 ON_4fPoint operator-(const ON_4fPoint&) const; // difference w = sqrt(w1*w2) 00359 00360 float operator*(const ON_4fPoint&) const; 00361 00362 // projective comparison 00363 // (i.e., [x,y,z,w] == [c*x,c*y,c*z,c*w] is true for nonzero c) 00364 bool operator==(ON_4fPoint) const; 00365 bool operator!=(const ON_4fPoint&) const; 00366 00367 // index operators mimic float[4] behavior 00368 float& operator[](int); 00369 float operator[](int) const; 00370 float& operator[](unsigned int); 00371 float operator[](unsigned int) const; 00372 00373 // set 4d point value 00374 void Set(float,float,float,float); 00375 00376 int MaximumCoordinateIndex() const; 00377 double MaximumCoordinate() const; // absolute value of maximum coordinate 00378 00379 void Zero(); // set all 4 coordinates to zero; 00380 bool Normalize(); // set so x^2 + y^2 + z^2 + w^2 = 1 00381 00382 // These transform the point in place. The transformation matrix acts on 00383 // the left of the point; i.e., result = transformation*point 00384 void Transform( 00385 const ON_Xform& 00386 ); 00387 }; 00388 00389 ON_DECL 00390 ON_4fPoint operator*(float, const ON_4fPoint&); 00391 00392 ON_DECL 00393 ON_4dPoint operator*(double, const ON_4fPoint&); 00394 00395 //////////////////////////////////////////////////////////////// 00396 // 00397 // ON_2fVector 00398 // 00399 class ON_CLASS ON_2fVector 00400 { 00401 public: 00402 float x, y; 00403 00404 static const ON_2fVector ZeroVector; // (0.0f,0.0f) 00405 static const ON_2fVector XAxis; // (1.0f,0.0f) 00406 static const ON_2fVector YAxis; // (0.0f,1.0f) 00407 00408 // Description: 00409 // A index driven function to get unit axis vectors. 00410 // Parameters: 00411 // index - [in] 0 returns (1,0), 1 returns (0,1) 00412 // Returns: 00413 // Unit 3d vector with vector[i] = (i==index)?1:0; 00414 static const ON_2fVector& UnitVector( 00415 int // index 00416 ); 00417 00418 // use implicit destructor, copy constructor 00419 ON_2fVector(); // x,y not initialized 00420 ON_2fVector(float x,float y); 00421 ON_2fVector(const ON_2fPoint& ); // from 2f point 00422 ON_2fVector(const ON_3fPoint& ); // from 3f point 00423 ON_2fVector(const ON_4fPoint& ); // from 4f point 00424 ON_2fVector(const ON_3fVector& ); // from 3f vector 00425 ON_2fVector(const float*); // from float[2] array 00426 00427 ON_2fVector(const ON_2dPoint& ); // from 2d point 00428 ON_2fVector(const ON_3dPoint& ); // from 3d point 00429 ON_2fVector(const ON_4dPoint& ); // from 4d point 00430 ON_2fVector(const ON_2dVector& ); // from 2d vector 00431 ON_2fVector(const ON_3dVector& ); // from 3d vector 00432 ON_2fVector(const double*); // from double[2] array 00433 00434 // (float*) conversion operators 00435 operator float*(); 00436 operator const float*() const; 00437 00438 // use implicit operator=(const ON_2fVector&) 00439 ON_2fVector& operator=(const ON_2fPoint&); 00440 ON_2fVector& operator=(const ON_3fPoint&); 00441 ON_2fVector& operator=(const ON_3fVector&); 00442 ON_2fVector& operator=(const float*); // point = float[2] support 00443 00444 ON_2fVector& operator=(const ON_2dPoint&); 00445 ON_2fVector& operator=(const ON_3dPoint&); 00446 ON_2fVector& operator=(const ON_2dVector&); 00447 ON_2fVector& operator=(const ON_3dVector&); 00448 ON_2fVector& operator=(const double*); // point = double[2] support 00449 00450 ON_2fVector operator-() const; 00451 00452 ON_2fVector& operator*=(float); 00453 ON_2fVector& operator/=(float); 00454 ON_2fVector& operator+=(const ON_2fVector&); 00455 ON_2fVector& operator-=(const ON_2fVector&); 00456 00457 float operator*(const ON_2fVector&) const; // inner (dot) product 00458 float operator*(const ON_2fPoint&) const; // inner (dot) product point acting as a vector 00459 double operator*(const ON_2dVector&) const; // inner (dot) product 00460 00461 ON_2fVector operator*(int) const; 00462 ON_2fVector operator/(int) const; 00463 ON_2fVector operator*(float) const; 00464 ON_2fVector operator/(float) const; 00465 ON_2dVector operator*(double) const; 00466 ON_2dVector operator/(double) const; 00467 00468 ON_2fVector operator+(const ON_2fVector&) const; 00469 ON_2fPoint operator+(const ON_2fPoint&) const; 00470 ON_2fVector operator-(const ON_2fVector&) const; 00471 ON_2fPoint operator-(const ON_2fPoint&) const; 00472 ON_3fVector operator+(const ON_3fVector&) const; 00473 ON_3fPoint operator+(const ON_3fPoint&) const; 00474 ON_3fVector operator-(const ON_3fVector&) const; 00475 ON_3fPoint operator-(const ON_3fPoint&) const; 00476 00477 ON_2dVector operator+(const ON_2dVector&) const; 00478 ON_2dPoint operator+(const ON_2dPoint&) const; 00479 ON_2dVector operator-(const ON_2dVector&) const; 00480 ON_2dPoint operator-(const ON_2dPoint&) const; 00481 ON_3dVector operator+(const ON_3dVector&) const; 00482 ON_3dPoint operator+(const ON_3dPoint&) const; 00483 ON_3dVector operator-(const ON_3dVector&) const; 00484 ON_3dPoint operator-(const ON_3dPoint&) const; 00485 00486 float operator*(const ON_4fPoint&) const; 00487 00488 bool operator==(const ON_2fVector&) const; 00489 bool operator!=(const ON_2fVector&) const; 00490 00491 // dictionary order comparisons 00492 bool operator<=(const ON_2fVector&) const; 00493 bool operator>=(const ON_2fVector&) const; 00494 bool operator<(const ON_2fVector&) const; 00495 bool operator>(const ON_2fVector&) const; 00496 00497 // index operators mimic float[2] behavior 00498 float& operator[](int); 00499 float operator[](int) const; 00500 float& operator[](unsigned int); 00501 float operator[](unsigned int) const; 00502 00503 // set 2d vector value 00504 void Set(float,float); 00505 00506 int MaximumCoordinateIndex() const; 00507 double MaximumCoordinate() const; // absolute value of maximum coordinate 00508 00509 double LengthSquared() const; 00510 double Length() const; 00511 00512 bool Decompose( // Computes a, b such that this vector = a*X + b*Y 00513 // Returns false if unable to solve for a,b. This happens 00514 // when X,Y is not really a basis. 00515 // 00516 // If X,Y is known to be an orthonormal frame, 00517 // then a = V*X, b = V*Y will compute 00518 // the same result more quickly. 00519 const ON_2fVector&, // X 00520 const ON_2fVector&, // Y 00521 double*, // a 00522 double* // b 00523 ) const; 00524 00525 int IsParallelTo( 00526 // returns 1: this and other vectors are parallel 00527 // -1: this and other vectors are anti-parallel 00528 // 0: this and other vectors are not parallel 00529 // or at least one of the vectors is zero 00530 const ON_2fVector&, // other vector 00531 double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians) 00532 ) const; 00533 00534 bool IsPerpendicularTo( 00535 // returns true: this and other vectors are perpendicular 00536 // false: this and other vectors are not perpendicular 00537 // or at least one of the vectors is zero 00538 const ON_2fVector&, // other vector 00539 double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians) 00540 ) const; 00541 00542 void Zero(); // set all coordinates to zero; 00543 void Reverse(); // negate all coordinates 00544 bool Unitize(); // returns false if vector has zero length 00545 bool IsUnitVector() const; 00546 00547 // Description: 00548 // Test a vector to see if it is very short 00549 // 00550 // Parameters: 00551 // tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero 00552 // value used as the coordinate zero tolerance. 00553 // 00554 // Returns: 00555 // ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol ) 00556 // 00557 bool IsTiny( 00558 double = ON_ZERO_TOLERANCE // tiny_tol 00559 ) const; 00560 00561 // Returns: 00562 // true if vector is the zero vector. 00563 bool IsZero() const; 00564 00565 // set this vector to be perpendicular to another vector 00566 bool PerpendicularTo( // Result is not unitized. 00567 // returns false if input vector is zero 00568 const ON_2fVector& 00569 ); 00570 00571 // set this vector to be perpendicular to a line defined by 2 points 00572 bool PerpendicularTo( 00573 const ON_2fPoint&, 00574 const ON_2fPoint& 00575 ); 00576 }; 00577 00578 ON_DECL 00579 ON_2fVector operator*(int, const ON_2fVector&); 00580 00581 ON_DECL 00582 ON_2fVector operator*(float, const ON_2fVector&); 00583 00584 ON_DECL 00585 ON_2dVector operator*(double, const ON_2fVector&); 00586 00587 /////////////////////////////////////////////////////////////// 00588 // 00589 // ON_2fVector utilities 00590 // 00591 00592 ON_DECL 00593 float 00594 ON_DotProduct( 00595 const ON_2fVector&, 00596 const ON_2fVector& 00597 ); 00598 00599 ON_DECL 00600 ON_3fVector 00601 ON_CrossProduct( 00602 const ON_2fVector&, 00603 const ON_2fVector& 00604 ); 00605 00606 ON_DECL 00607 bool 00608 ON_IsOrthogonalFrame( // true if X, Y are nonzero and mutually perpendicular 00609 const ON_2fVector&, // X 00610 const ON_2fVector& // Y 00611 ); 00612 00613 ON_DECL 00614 bool 00615 ON_IsOrthonormalFrame( // true if X, Y are orthogonal and unit length 00616 const ON_2fVector&, // X 00617 const ON_2fVector& // Y 00618 ); 00619 00620 ON_DECL 00621 bool 00622 ON_IsRightHandFrame( // true if X, Y are orthonormal and right handed 00623 const ON_2fVector&, // X 00624 const ON_2fVector& // Y 00625 ); 00626 00627 //////////////////////////////////////////////////////////////// 00628 // 00629 // ON_3fVector 00630 // 00631 class ON_CLASS ON_3fVector 00632 { 00633 public: 00634 float x, y, z; 00635 00636 static const ON_3fVector ZeroVector; // (0.0f,0.0f,0.0f) 00637 static const ON_3fVector XAxis; // (1.0f,0.0f,0.0f) 00638 static const ON_3fVector YAxis; // (0.0f,1.0f,0.0f) 00639 static const ON_3fVector ZAxis; // (0.0f,0.0f,1.0f) 00640 00641 // Description: 00642 // A index driven function to get unit axis vectors. 00643 // Parameters: 00644 // index - [in] 0 returns (1,0,0), 1 returns (0,1,0) 00645 // 2 returns (0,0,1) 00646 // Returns: 00647 // Unit 3d vector with vector[i] = (i==index)?1:0; 00648 static const ON_3fVector& UnitVector( 00649 int // index 00650 ); 00651 00652 // use implicit destructor, copy constructor 00653 ON_3fVector(); // x,y,z not initialized 00654 ON_3fVector(float x,float y,float z); 00655 00656 ON_3fVector(const ON_2fPoint& ); // from 2f point 00657 ON_3fVector(const ON_3fPoint& ); // from 3f point 00658 ON_3fVector(const ON_4fPoint& ); // from 4f point 00659 ON_3fVector(const ON_2fVector& ); // from 2f vector 00660 ON_3fVector(const float*); // from float[3] array 00661 00662 ON_3fVector(const ON_2dPoint& ); // from 2d point 00663 ON_3fVector(const ON_3dPoint& ); // from 3d point 00664 ON_3fVector(const ON_4dPoint& ); // from 4d point 00665 ON_3fVector(const ON_2dVector& ); // from 2d vector 00666 ON_3fVector(const ON_3dVector& ); // from 3d vector 00667 ON_3fVector(const double*); // from double[3] array 00668 00669 // (float*) conversion operators 00670 operator float*(); 00671 operator const float*() const; 00672 00673 // use implicit operator=(const ON_3fVector&) 00674 ON_3fVector& operator=(const ON_2fPoint&); 00675 ON_3fVector& operator=(const ON_3fPoint&); 00676 ON_3fVector& operator=(const ON_4fPoint&); 00677 ON_3fVector& operator=(const ON_2fVector&); 00678 ON_3fVector& operator=(const float*); // point = float[3] support 00679 00680 ON_3fVector& operator=(const ON_2dPoint&); 00681 ON_3fVector& operator=(const ON_3dPoint&); 00682 ON_3fVector& operator=(const ON_4dPoint&); 00683 ON_3fVector& operator=(const ON_2dVector&); 00684 ON_3fVector& operator=(const ON_3dVector&); 00685 ON_3fVector& operator=(const double*); // point = double[3] support 00686 00687 ON_3fVector operator-() const; 00688 00689 ON_3fVector& operator*=(float); 00690 ON_3fVector& operator/=(float); 00691 ON_3fVector& operator+=(const ON_3fVector&); 00692 ON_3fVector& operator-=(const ON_3fVector&); 00693 00694 float operator*(const ON_3fVector&) const; // inner (dot) product 00695 float operator*(const ON_3fPoint&) const; // inner (dot) product (point acting as a vector) 00696 double operator*(const ON_3dVector&) const; // inner (dot) product 00697 00698 ON_3fVector operator*(int) const; 00699 ON_3fVector operator/(int) const; 00700 ON_3fVector operator*(float) const; 00701 ON_3fVector operator/(float) const; 00702 ON_3dVector operator*(double) const; 00703 ON_3dVector operator/(double) const; 00704 00705 ON_3fVector operator+(const ON_3fVector&) const; 00706 ON_3fPoint operator+(const ON_3fPoint&) const; 00707 ON_3fVector operator-(const ON_3fVector&) const; 00708 ON_3fPoint operator-(const ON_3fPoint&) const; 00709 ON_3fVector operator+(const ON_2fVector&) const; 00710 ON_3fPoint operator+(const ON_2fPoint&) const; 00711 ON_3fVector operator-(const ON_2fVector&) const; 00712 ON_3fPoint operator-(const ON_2fPoint&) const; 00713 00714 ON_3dVector operator+(const ON_3dVector&) const; 00715 ON_3dPoint operator+(const ON_3dPoint&) const; 00716 ON_3dVector operator-(const ON_3dVector&) const; 00717 ON_3dPoint operator-(const ON_3dPoint&) const; 00718 ON_3dVector operator+(const ON_2dVector&) const; 00719 ON_3dPoint operator+(const ON_2dPoint&) const; 00720 ON_3dVector operator-(const ON_2dVector&) const; 00721 ON_3dPoint operator-(const ON_2dPoint&) const; 00722 00723 float operator*(const ON_4fPoint&) const; 00724 00725 bool operator==(const ON_3fVector&) const; 00726 bool operator!=(const ON_3fVector&) const; 00727 00728 // dictionary order comparisons 00729 bool operator<=(const ON_3fVector&) const; 00730 bool operator>=(const ON_3fVector&) const; 00731 bool operator<(const ON_3fVector&) const; 00732 bool operator>(const ON_3fVector&) const; 00733 00734 // index operators mimic float[3] behavior 00735 float& operator[](int); 00736 float operator[](int) const; 00737 float& operator[](unsigned int); 00738 float operator[](unsigned int) const; 00739 00740 // set 3d vector value 00741 void Set(float,float,float); 00742 00743 int MaximumCoordinateIndex() const; 00744 double MaximumCoordinate() const; // absolute value of maximum coordinate 00745 00746 double LengthSquared() const; 00747 double Length() const; 00748 00749 bool IsPerpendicularTo( 00750 // returns true: this and other vectors are perpendicular 00751 // false: this and other vectors are not perpendicular 00752 // or at least one of the vectors is zero 00753 const ON_3fVector&, // other vector 00754 double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians) 00755 ) const; 00756 00757 double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d vectors 00758 00759 void Zero(); // set all coordinates to zero 00760 void Reverse(); // negate all coordinates 00761 bool Unitize(); // returns false if vector has zero length 00762 bool IsUnitVector() const; 00763 00764 // Description: 00765 // Test a vector to see if it is very short 00766 // 00767 // Parameters: 00768 // tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero 00769 // value used as the coordinate zero tolerance. 00770 // 00771 // Returns: 00772 // ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol && fabs(z) <= tiny_tol ) 00773 // 00774 bool IsTiny( 00775 double = ON_ZERO_TOLERANCE // tiny_tol 00776 ) const; 00777 00778 // Returns: 00779 // true if vector is the zero vector. 00780 bool IsZero() const; 00781 00782 // set this vector to be perpendicular to another vector 00783 bool PerpendicularTo( // Result is not unitized. 00784 // returns false if input vector is zero 00785 const ON_3fVector& 00786 ); 00787 00788 // These transform the vector in place. The transformation matrix acts on 00789 // the left of the vector; i.e., result = transformation*vector 00790 void Transform( 00791 const ON_Xform& // can use ON_Xform here 00792 ); 00793 00794 void Rotate( 00795 double, // angle in radians 00796 const ON_3fVector& // axis of rotation 00797 ); 00798 00799 void Rotate( 00800 double, // sin(angle) 00801 double, // cos(angle) 00802 const ON_3fVector& // axis of rotation 00803 ); 00804 }; 00805 00806 ON_DECL 00807 ON_3fVector operator*(int, const ON_3fVector&); 00808 00809 ON_DECL 00810 ON_3fVector operator*(float, const ON_3fVector&); 00811 00812 ON_DECL 00813 ON_3dVector operator*(double, const ON_3fVector&); 00814 00815 /////////////////////////////////////////////////////////////// 00816 // 00817 // ON_3fVector utilities 00818 // 00819 00820 ON_DECL 00821 float 00822 ON_DotProduct( 00823 const ON_3fVector&, 00824 const ON_3fVector& 00825 ); 00826 00827 00828 ON_DECL 00829 ON_3fVector 00830 ON_CrossProduct( 00831 const ON_3fVector&, 00832 const ON_3fVector& 00833 ); 00834 00835 ON_DECL 00836 ON_3fVector 00837 ON_CrossProduct( // 3d cross product for old fashioned arrays 00838 const float*, // array of 3d floats 00839 const float* // array of 3d floats 00840 ); 00841 00842 ON_DECL 00843 float 00844 ON_TripleProduct( 00845 const ON_3fVector&, 00846 const ON_3fVector&, 00847 const ON_3fVector& 00848 ); 00849 00850 ON_DECL 00851 float 00852 ON_TripleProduct( // 3d triple product for old fashioned arrays 00853 const float*, // array of 3d floats 00854 const float*, // array of 3d floats 00855 const float* // array of 3d floats 00856 ); 00857 00858 ON_DECL 00859 bool 00860 ON_IsOrthogonalFrame( // true if X, Y, Z are nonzero and mutually perpendicular 00861 const ON_3fVector&, // X 00862 const ON_3fVector&, // Y 00863 const ON_3fVector& // Z 00864 ); 00865 00866 ON_DECL 00867 bool 00868 ON_IsOrthonormalFrame( // true if X, Y, Z are orthogonal and unit length 00869 const ON_3fVector&, // X 00870 const ON_3fVector&, // Y 00871 const ON_3fVector& // Z 00872 ); 00873 00874 ON_DECL 00875 bool 00876 ON_IsRightHandFrame( // true if X, Y, Z are orthonormal and right handed 00877 const ON_3fVector&, // X 00878 const ON_3fVector&, // Y 00879 const ON_3fVector& // Z 00880 ); 00881 00882 /////////////////////////////////////////////////////////////// 00883 // 00884 // common points and vectors 00885 // 00886 00887 // ON_forigin is OBSOLETE - use ON_3fPoint::Origin 00888 extern ON_EXTERN_DECL const ON_3fPoint ON_forigin; // (0.0, 0.0, 0.0) 00889 00890 // ON_fxaxis is OBSOLETE - use ON_3fPoint::XAxis 00891 extern ON_EXTERN_DECL const ON_3fVector ON_fxaxis; // (1.0, 0.0, 0.0) 00892 00893 // ON_fyaxis is OBSOLETE - use ON_3fVector::YAxis 00894 extern ON_EXTERN_DECL const ON_3fVector ON_fyaxis; // (0.0, 1.0, 0.0) 00895 00896 // ON_fzaxis is OBSOLETE - use ON_3fVector::ZAxis 00897 extern ON_EXTERN_DECL const ON_3fVector ON_fzaxis; // (0.0, 0.0, 1.0) 00898 00899 00900 #endif