Point Cloud Library (PCL)  1.9.1-dev
opennurbs_fpoint.h
1 /* \$NoKeywords: \$ */
2 /*
3 //
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16
17 ////////////////////////////////////////////////////////////////
18 //
19 // defines float precision point, vector, and array classes
20 //
21 ////////////////////////////////////////////////////////////////
22 #if !defined(ON_FPOINT_INC_)
23 #define ON_FPOINT_INC_
24
25 class ON_Xform;
26
27 class ON_2fPoint;
28 class ON_3fPoint;
29 class ON_4fPoint;
30
31 class ON_2fVector;
32 class ON_3fVector;
33
34 ////////////////////////////////////////////////////////////////
35 //
36 // ON_2fPoint
37 //
38 class ON_CLASS ON_2fPoint
39 {
40 public:
41  float x, y;
42
43  static const ON_2fPoint Origin; // (0.0f,0.0f)
44
45  // use implicit destructor, copy constructor
46  ON_2fPoint(); // x,y not initialized
47  ON_2fPoint(float x,float y);
48
49  ON_2fPoint(const ON_3fPoint& ); // from 3f point
50  ON_2fPoint(const ON_4fPoint& ); // from 4f point
51  ON_2fPoint(const ON_2fVector& ); // from 2f vector
52  ON_2fPoint(const ON_3fVector& ); // from 3f vector
53  ON_2fPoint(const float*); // from float[2] array
54
55  ON_2fPoint(const ON_2dPoint& ); // from 2d point
56  ON_2fPoint(const ON_3dPoint& ); // from 3d point
57  ON_2fPoint(const ON_4dPoint& ); // from 4d point
58  ON_2fPoint(const ON_2dVector& ); // from 2d vector
59  ON_2fPoint(const ON_3dVector& ); // from 3d vector
60  ON_2fPoint(const double*); // from double[2] array
61
62  // (float*) conversion operators
63  operator float*();
64  operator const float*() const;
65
66  // use implicit operator=(const ON_2fPoint&)
67  ON_2fPoint& operator=(const ON_3fPoint&);
68  ON_2fPoint& operator=(const ON_4fPoint&);
69  ON_2fPoint& operator=(const ON_2fVector&);
70  ON_2fPoint& operator=(const ON_3fVector&);
71  ON_2fPoint& operator=(const float*); // point = float[2] support
72
73  ON_2fPoint& operator=(const ON_2dPoint&);
74  ON_2fPoint& operator=(const ON_3dPoint&);
75  ON_2fPoint& operator=(const ON_4dPoint&);
76  ON_2fPoint& operator=(const ON_2dVector&);
77  ON_2fPoint& operator=(const ON_3dVector&);
78  ON_2fPoint& operator=(const double*); // point = double[2] support
79
80  ON_2fPoint& operator*=(float);
81  ON_2fPoint& operator/=(float);
82  ON_2fPoint& operator+=(const ON_2fPoint&);
83  ON_2fPoint& operator+=(const ON_2fVector&);
84  ON_2fPoint& operator+=(const ON_3fVector&);
85  ON_2fPoint& operator-=(const ON_2fPoint&);
86  ON_2fPoint& operator-=(const ON_2fVector&);
87  ON_2fPoint& operator-=(const ON_3fVector&);
88
89  ON_2fPoint operator*(int) const;
90  ON_2fPoint operator/(int) const;
91  ON_2fPoint operator*(float) const;
92  ON_2fPoint operator/(float) const;
93  ON_2dPoint operator*(double) const;
94  ON_2dPoint operator/(double) const;
95
96  ON_2fPoint operator+(const ON_2fPoint&) const;
97  ON_2fPoint operator+(const ON_2fVector&) const;
98  ON_2fVector operator-(const ON_2fPoint&) const;
99  ON_2fPoint operator-(const ON_2fVector&) const;
100  ON_3fPoint operator+(const ON_3fPoint&) const;
101  ON_3fPoint operator+(const ON_3fVector&) const;
102  ON_3fVector operator-(const ON_3fPoint&) const;
103  ON_3fPoint operator-(const ON_3fVector&) const;
104
105  ON_2dPoint operator+(const ON_2dPoint&) const;
106  ON_2dPoint operator+(const ON_2dVector&) const;
107  ON_2dVector operator-(const ON_2dPoint&) const;
108  ON_2dPoint operator-(const ON_2dVector&) const;
109  ON_3dPoint operator+(const ON_3dPoint&) const;
110  ON_3dPoint operator+(const ON_3dVector&) const;
111  ON_3dVector operator-(const ON_3dPoint&) const;
112  ON_3dPoint operator-(const ON_3dVector&) const;
113
114  float operator*(const ON_2fPoint&) const; // for points acting as vectors
115  float operator*(const ON_2fVector&) const; // for points acting as vectors
116  float operator*(const ON_4fPoint&) const;
117
118  bool operator==(const ON_2fPoint&) const;
119  bool operator!=(const ON_2fPoint&) const;
120
121  // dictionary order comparisons
122  bool operator<=(const ON_2fPoint&) const;
123  bool operator>=(const ON_2fPoint&) const;
124  bool operator<(const ON_2fPoint&) const;
125  bool operator>(const ON_2fPoint&) const;
126
127  // index operators mimic float[2] behavior
128  float& operator[](int);
129  float operator[](int) const;
130  float& operator[](unsigned int);
131  float operator[](unsigned int) const;
132
133  // set 2d point value
134  void Set(float,float);
135
136  double DistanceTo( const ON_2fPoint& ) const;
137
138  int MaximumCoordinateIndex() const;
139  double MaximumCoordinate() const; // absolute value of maximum coordinate
140
141  void Zero(); // set all coordinates to zero;
142
143  // These transform the point in place. The transformation matrix acts on
144  // the left of the point; i.e., result = transformation*point
145  void Transform(
146  const ON_Xform&
147  );
148
149  void Rotate( // rotatation in XY plane
150  double, // angle in radians
151  const ON_2fPoint& // center of rotation
152  );
153
154  void Rotate( // rotatation in XY plane
155  double, // sin(angle)
156  double, // cos(angle)
157  const ON_2fPoint& // center of rotation
158  );
159 };
160
161 ON_DECL
162 ON_2fPoint operator*(int, const ON_2fPoint&);
163
164 ON_DECL
165 ON_2fPoint operator*(float, const ON_2fPoint&);
166
167 ON_DECL
168 ON_2dPoint operator*(double, const ON_2fPoint&);
169
170 ////////////////////////////////////////////////////////////////
171 //
172 // ON_3fPoint
173 //
174 class ON_CLASS ON_3fPoint
175 {
176 public:
177  float x, y, z;
178
179  static const ON_3fPoint Origin; // (0.0f,0.0f,0.0f)
180
181  // use implicit destructor, copy constructor
182  ON_3fPoint(); // x,y,z not initialized
183  ON_3fPoint(float x,float y,float z);
184  ON_3fPoint(const ON_2fPoint& ); // from 2f point
185  ON_3fPoint(const ON_4fPoint& ); // from 4f point
186  ON_3fPoint(const ON_2fVector& ); // from 2f vector
187  ON_3fPoint(const ON_3fVector& ); // from 3f vector
188  ON_3fPoint(const float*); // from float[3] array
189
190  ON_3fPoint(const ON_2dPoint& ); // from 2d point
191  ON_3fPoint(const ON_3dPoint& ); // from 3d point
192  ON_3fPoint(const ON_4dPoint& ); // from 4d point
193  ON_3fPoint(const ON_2dVector& ); // from 2d vector
194  ON_3fPoint(const ON_3dVector& ); // from 3d vector
195  ON_3fPoint(const double*); // from double[3] array
196
197  // (float*) conversion operators
198  operator float*();
199  operator const float*() const;
200
201  // use implicit operator=(const ON_3fPoint&)
202  ON_3fPoint& operator=(const ON_2fPoint&);
203  ON_3fPoint& operator=(const ON_4fPoint&);
204  ON_3fPoint& operator=(const ON_2fVector&);
205  ON_3fPoint& operator=(const ON_3fVector&);
206  ON_3fPoint& operator=(const float*); // point = float[3] support
207
208  ON_3fPoint& operator=(const ON_2dPoint&);
209  ON_3fPoint& operator=(const ON_3dPoint&);
210  ON_3fPoint& operator=(const ON_4dPoint&);
211  ON_3fPoint& operator=(const ON_2dVector&);
212  ON_3fPoint& operator=(const ON_3dVector&);
213  ON_3fPoint& operator=(const double*); // point = double[3] support
214
215  ON_3fPoint& operator*=(float);
216  ON_3fPoint& operator/=(float);
217  ON_3fPoint& operator+=(const ON_3fPoint&);
218  ON_3fPoint& operator+=(const ON_3fVector&);
219  ON_3fPoint& operator-=(const ON_3fPoint&);
220  ON_3fPoint& operator-=(const ON_3fVector&);
221
222  ON_3fPoint operator*(int) const;
223  ON_3fPoint operator/(int) const;
224  ON_3fPoint operator*(float) const;
225  ON_3fPoint operator/(float) const;
226  ON_3dPoint operator*(double) const;
227  ON_3dPoint operator/(double) const;
228
229  ON_3fPoint operator+(const ON_3fPoint&) const;
230  ON_3fPoint operator+(const ON_3fVector&) const;
231  ON_3fVector operator-(const ON_3fPoint&) const;
232  ON_3fPoint operator-(const ON_3fVector&) const;
233  ON_3fPoint operator+(const ON_2fPoint&) const;
234  ON_3fPoint operator+(const ON_2fVector&) const;
235  ON_3fVector operator-(const ON_2fPoint&) const;
236  ON_3fPoint operator-(const ON_2fVector&) const;
237
238  ON_3dPoint operator+(const ON_3dPoint&) const;
239  ON_3dPoint operator+(const ON_3dVector&) const;
240  ON_3dVector operator-(const ON_3dPoint&) const;
241  ON_3dPoint operator-(const ON_3dVector&) const;
242  ON_3dPoint operator+(const ON_2dPoint&) const;
243  ON_3dPoint operator+(const ON_2dVector&) const;
244  ON_3dVector operator-(const ON_2dPoint&) const;
245  ON_3dPoint operator-(const ON_2dVector&) const;
246
247  float operator*(const ON_3fPoint&) const; // for points acting as vectors
248  float operator*(const ON_3fVector&) const; // for points acting as vectors
249  float operator*(const ON_4fPoint&) const;
250
251  bool operator==(const ON_3fPoint&) const;
252  bool operator!=(const ON_3fPoint&) const;
253
254  // dictionary order comparisons
255  bool operator<=(const ON_3fPoint&) const;
256  bool operator>=(const ON_3fPoint&) const;
257  bool operator<(const ON_3fPoint&) const;
258  bool operator>(const ON_3fPoint&) const;
259
260  // index operators mimic float[3] behavior
261  float& operator[](int);
262  float operator[](int) const;
263  float& operator[](unsigned int);
264  float operator[](unsigned int) const;
265
266  // set 3d point value
267  void Set(float,float,float);
268
269  double DistanceTo( const ON_3fPoint& ) const;
270
271  int MaximumCoordinateIndex() const;
272  double MaximumCoordinate() const; // absolute value of maximum coordinate
273  double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d points
274
275  void Zero(); // set all coordinates to zero;
276
277  // These transform the point in place. The transformation matrix acts on
278  // the left of the point; i.e., result = transformation*point
279  void Transform(
280  const ON_Xform&
281  );
282
283  void Rotate(
284  double, // angle in radians
285  const ON_3fVector&, // axis of rotation
286  const ON_3fPoint& // center of rotation
287  );
288
289  void Rotate(
290  double, // sin(angle)
291  double, // cos(angle)
292  const ON_3fVector&, // axis of rotation
293  const ON_3fPoint& // center of rotation
294  );
295 };
296
297 ON_DECL
298 ON_3fPoint operator*(int, const ON_3fPoint&);
299
300 ON_DECL
301 ON_3fPoint operator*(float, const ON_3fPoint&);
302
303 ON_DECL
304 ON_3dPoint operator*(double, const ON_3fPoint&);
305
306 ////////////////////////////////////////////////////////////////
307 //
308 // ON_4fPoint (homogeneous coordinates)
309 //
310 class ON_CLASS ON_4fPoint
311 {
312 public:
313  float x, y, z, w;
314
315  // use implicit destructor, copy constructor
316  ON_4fPoint(); // x,y,z,w not initialized
317  ON_4fPoint(float x,float y,float z,float w);
318
319  ON_4fPoint(const ON_2fPoint& ); // from 2f point
320  ON_4fPoint(const ON_3fPoint& ); // from 3f point
321  ON_4fPoint(const ON_2fVector& ); // from 2f vector
322  ON_4fPoint(const ON_3fVector& ); // from 3f vector
323  ON_4fPoint(const float*); // from float[4] array
324
325  ON_4fPoint(const ON_2dPoint& ); // from 2d point
326  ON_4fPoint(const ON_3dPoint& ); // from 3d point
327  ON_4fPoint(const ON_4dPoint& ); // from 4d point
328  ON_4fPoint(const ON_2dVector& ); // from 2d vector
329  ON_4fPoint(const ON_3dVector& ); // from 3d vector
330  ON_4fPoint(const double*); // from double[4] array
331
332  // (float*) conversion operators
333  operator float*();
334  operator const float*() const;
335
336  // use implicit operator=(const ON_4fPoint&)
337  ON_4fPoint& operator=(const ON_2fPoint&);
338  ON_4fPoint& operator=(const ON_3fPoint&);
339  ON_4fPoint& operator=(const ON_2fVector&);
340  ON_4fPoint& operator=(const ON_3fVector&);
341  ON_4fPoint& operator=(const float*); // point = float[4] support
342
343  ON_4fPoint& operator=(const ON_2dPoint&);
344  ON_4fPoint& operator=(const ON_3dPoint&);
345  ON_4fPoint& operator=(const ON_4dPoint&);
346  ON_4fPoint& operator=(const ON_2dVector&);
347  ON_4fPoint& operator=(const ON_3dVector&);
348  ON_4fPoint& operator=(const double*); // point = double[4] support
349
350  ON_4fPoint& operator*=(float);
351  ON_4fPoint& operator/=(float);
352  ON_4fPoint& operator+=(const ON_4fPoint&);
353  ON_4fPoint& operator-=(const ON_4fPoint&);
354
355  ON_4fPoint operator*(float) const;
356  ON_4fPoint operator/(float) const;
357  ON_4fPoint operator+(const ON_4fPoint&) const; // sum w = sqrt(w1*w2)
358  ON_4fPoint operator-(const ON_4fPoint&) const; // difference w = sqrt(w1*w2)
359
360  float operator*(const ON_4fPoint&) const;
361
362  // projective comparison
363  // (i.e., [x,y,z,w] == [c*x,c*y,c*z,c*w] is true for nonzero c)
364  bool operator==(ON_4fPoint) const;
365  bool operator!=(const ON_4fPoint&) const;
366
367  // index operators mimic float[4] behavior
368  float& operator[](int);
369  float operator[](int) const;
370  float& operator[](unsigned int);
371  float operator[](unsigned int) const;
372
373  // set 4d point value
374  void Set(float,float,float,float);
375
376  int MaximumCoordinateIndex() const;
377  double MaximumCoordinate() const; // absolute value of maximum coordinate
378
379  void Zero(); // set all 4 coordinates to zero;
380  bool Normalize(); // set so x^2 + y^2 + z^2 + w^2 = 1
381
382  // These transform the point in place. The transformation matrix acts on
383  // the left of the point; i.e., result = transformation*point
384  void Transform(
385  const ON_Xform&
386  );
387 };
388
389 ON_DECL
390 ON_4fPoint operator*(float, const ON_4fPoint&);
391
392 ON_DECL
393 ON_4dPoint operator*(double, const ON_4fPoint&);
394
395 ////////////////////////////////////////////////////////////////
396 //
397 // ON_2fVector
398 //
399 class ON_CLASS ON_2fVector
400 {
401 public:
402  float x, y;
403
404  static const ON_2fVector ZeroVector; // (0.0f,0.0f)
405  static const ON_2fVector XAxis; // (1.0f,0.0f)
406  static const ON_2fVector YAxis; // (0.0f,1.0f)
407
408  // Description:
409  // A index driven function to get unit axis vectors.
410  // Parameters:
411  // index - [in] 0 returns (1,0), 1 returns (0,1)
412  // Returns:
413  // Unit 3d vector with vector[i] = (i==index)?1:0;
414  static const ON_2fVector& UnitVector(
415  int // index
416  );
417
418  // use implicit destructor, copy constructor
419  ON_2fVector(); // x,y not initialized
420  ON_2fVector(float x,float y);
421  ON_2fVector(const ON_2fPoint& ); // from 2f point
422  ON_2fVector(const ON_3fPoint& ); // from 3f point
423  ON_2fVector(const ON_4fPoint& ); // from 4f point
424  ON_2fVector(const ON_3fVector& ); // from 3f vector
425  ON_2fVector(const float*); // from float[2] array
426
427  ON_2fVector(const ON_2dPoint& ); // from 2d point
428  ON_2fVector(const ON_3dPoint& ); // from 3d point
429  ON_2fVector(const ON_4dPoint& ); // from 4d point
430  ON_2fVector(const ON_2dVector& ); // from 2d vector
431  ON_2fVector(const ON_3dVector& ); // from 3d vector
432  ON_2fVector(const double*); // from double[2] array
433
434  // (float*) conversion operators
435  operator float*();
436  operator const float*() const;
437
438  // use implicit operator=(const ON_2fVector&)
439  ON_2fVector& operator=(const ON_2fPoint&);
440  ON_2fVector& operator=(const ON_3fPoint&);
441  ON_2fVector& operator=(const ON_3fVector&);
442  ON_2fVector& operator=(const float*); // point = float[2] support
443
444  ON_2fVector& operator=(const ON_2dPoint&);
445  ON_2fVector& operator=(const ON_3dPoint&);
446  ON_2fVector& operator=(const ON_2dVector&);
447  ON_2fVector& operator=(const ON_3dVector&);
448  ON_2fVector& operator=(const double*); // point = double[2] support
449
450  ON_2fVector operator-() const;
451
452  ON_2fVector& operator*=(float);
453  ON_2fVector& operator/=(float);
454  ON_2fVector& operator+=(const ON_2fVector&);
455  ON_2fVector& operator-=(const ON_2fVector&);
456
457  float operator*(const ON_2fVector&) const; // inner (dot) product
458  float operator*(const ON_2fPoint&) const; // inner (dot) product point acting as a vector
459  double operator*(const ON_2dVector&) const; // inner (dot) product
460
461  ON_2fVector operator*(int) const;
462  ON_2fVector operator/(int) const;
463  ON_2fVector operator*(float) const;
464  ON_2fVector operator/(float) const;
465  ON_2dVector operator*(double) const;
466  ON_2dVector operator/(double) const;
467
468  ON_2fVector operator+(const ON_2fVector&) const;
469  ON_2fPoint operator+(const ON_2fPoint&) const;
470  ON_2fVector operator-(const ON_2fVector&) const;
471  ON_2fPoint operator-(const ON_2fPoint&) const;
472  ON_3fVector operator+(const ON_3fVector&) const;
473  ON_3fPoint operator+(const ON_3fPoint&) const;
474  ON_3fVector operator-(const ON_3fVector&) const;
475  ON_3fPoint operator-(const ON_3fPoint&) const;
476
477  ON_2dVector operator+(const ON_2dVector&) const;
478  ON_2dPoint operator+(const ON_2dPoint&) const;
479  ON_2dVector operator-(const ON_2dVector&) const;
480  ON_2dPoint operator-(const ON_2dPoint&) const;
481  ON_3dVector operator+(const ON_3dVector&) const;
482  ON_3dPoint operator+(const ON_3dPoint&) const;
483  ON_3dVector operator-(const ON_3dVector&) const;
484  ON_3dPoint operator-(const ON_3dPoint&) const;
485
486  float operator*(const ON_4fPoint&) const;
487
488  bool operator==(const ON_2fVector&) const;
489  bool operator!=(const ON_2fVector&) const;
490
491  // dictionary order comparisons
492  bool operator<=(const ON_2fVector&) const;
493  bool operator>=(const ON_2fVector&) const;
494  bool operator<(const ON_2fVector&) const;
495  bool operator>(const ON_2fVector&) const;
496
497  // index operators mimic float[2] behavior
498  float& operator[](int);
499  float operator[](int) const;
500  float& operator[](unsigned int);
501  float operator[](unsigned int) const;
502
503  // set 2d vector value
504  void Set(float,float);
505
506  int MaximumCoordinateIndex() const;
507  double MaximumCoordinate() const; // absolute value of maximum coordinate
508
509  double LengthSquared() const;
510  double Length() const;
511
512  bool Decompose( // Computes a, b such that this vector = a*X + b*Y
513  // Returns false if unable to solve for a,b. This happens
514  // when X,Y is not really a basis.
515  //
516  // If X,Y is known to be an orthonormal frame,
517  // then a = V*X, b = V*Y will compute
518  // the same result more quickly.
519  const ON_2fVector&, // X
520  const ON_2fVector&, // Y
521  double*, // a
522  double* // b
523  ) const;
524
525  int IsParallelTo(
526  // returns 1: this and other vectors are parallel
527  // -1: this and other vectors are anti-parallel
528  // 0: this and other vectors are not parallel
529  // or at least one of the vectors is zero
530  const ON_2fVector&, // other vector
531  double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
532  ) const;
533
534  bool IsPerpendicularTo(
535  // returns true: this and other vectors are perpendicular
536  // false: this and other vectors are not perpendicular
537  // or at least one of the vectors is zero
538  const ON_2fVector&, // other vector
539  double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
540  ) const;
541
542  void Zero(); // set all coordinates to zero;
543  void Reverse(); // negate all coordinates
544  bool Unitize(); // returns false if vector has zero length
545  bool IsUnitVector() const;
546
547  // Description:
548  // Test a vector to see if it is very short
549  //
550  // Parameters:
551  // tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero
552  // value used as the coordinate zero tolerance.
553  //
554  // Returns:
555  // ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol )
556  //
557  bool IsTiny(
558  double = ON_ZERO_TOLERANCE // tiny_tol
559  ) const;
560
561  // Returns:
562  // true if vector is the zero vector.
563  bool IsZero() const;
564
565  // set this vector to be perpendicular to another vector
566  bool PerpendicularTo( // Result is not unitized.
567  // returns false if input vector is zero
568  const ON_2fVector&
569  );
570
571  // set this vector to be perpendicular to a line defined by 2 points
572  bool PerpendicularTo(
573  const ON_2fPoint&,
574  const ON_2fPoint&
575  );
576 };
577
578 ON_DECL
579 ON_2fVector operator*(int, const ON_2fVector&);
580
581 ON_DECL
582 ON_2fVector operator*(float, const ON_2fVector&);
583
584 ON_DECL
585 ON_2dVector operator*(double, const ON_2fVector&);
586
587 ///////////////////////////////////////////////////////////////
588 //
589 // ON_2fVector utilities
590 //
591
592 ON_DECL
593 float
594 ON_DotProduct(
595  const ON_2fVector&,
596  const ON_2fVector&
597  );
598
599 ON_DECL
601 ON_CrossProduct(
602  const ON_2fVector&,
603  const ON_2fVector&
604  );
605
606 ON_DECL
607 bool
608 ON_IsOrthogonalFrame( // true if X, Y are nonzero and mutually perpendicular
609  const ON_2fVector&, // X
610  const ON_2fVector& // Y
611  );
612
613 ON_DECL
614 bool
615 ON_IsOrthonormalFrame( // true if X, Y are orthogonal and unit length
616  const ON_2fVector&, // X
617  const ON_2fVector& // Y
618  );
619
620 ON_DECL
621 bool
622 ON_IsRightHandFrame( // true if X, Y are orthonormal and right handed
623  const ON_2fVector&, // X
624  const ON_2fVector& // Y
625  );
626
627 ////////////////////////////////////////////////////////////////
628 //
629 // ON_3fVector
630 //
631 class ON_CLASS ON_3fVector
632 {
633 public:
634  float x, y, z;
635
636  static const ON_3fVector ZeroVector; // (0.0f,0.0f,0.0f)
637  static const ON_3fVector XAxis; // (1.0f,0.0f,0.0f)
638  static const ON_3fVector YAxis; // (0.0f,1.0f,0.0f)
639  static const ON_3fVector ZAxis; // (0.0f,0.0f,1.0f)
640
641  // Description:
642  // A index driven function to get unit axis vectors.
643  // Parameters:
644  // index - [in] 0 returns (1,0,0), 1 returns (0,1,0)
645  // 2 returns (0,0,1)
646  // Returns:
647  // Unit 3d vector with vector[i] = (i==index)?1:0;
648  static const ON_3fVector& UnitVector(
649  int // index
650  );
651
652  // use implicit destructor, copy constructor
653  ON_3fVector(); // x,y,z not initialized
654  ON_3fVector(float x,float y,float z);
655
656  ON_3fVector(const ON_2fPoint& ); // from 2f point
657  ON_3fVector(const ON_3fPoint& ); // from 3f point
658  ON_3fVector(const ON_4fPoint& ); // from 4f point
659  ON_3fVector(const ON_2fVector& ); // from 2f vector
660  ON_3fVector(const float*); // from float[3] array
661
662  ON_3fVector(const ON_2dPoint& ); // from 2d point
663  ON_3fVector(const ON_3dPoint& ); // from 3d point
664  ON_3fVector(const ON_4dPoint& ); // from 4d point
665  ON_3fVector(const ON_2dVector& ); // from 2d vector
666  ON_3fVector(const ON_3dVector& ); // from 3d vector
667  ON_3fVector(const double*); // from double[3] array
668
669  // (float*) conversion operators
670  operator float*();
671  operator const float*() const;
672
673  // use implicit operator=(const ON_3fVector&)
674  ON_3fVector& operator=(const ON_2fPoint&);
675  ON_3fVector& operator=(const ON_3fPoint&);
676  ON_3fVector& operator=(const ON_4fPoint&);
677  ON_3fVector& operator=(const ON_2fVector&);
678  ON_3fVector& operator=(const float*); // point = float[3] support
679
680  ON_3fVector& operator=(const ON_2dPoint&);
681  ON_3fVector& operator=(const ON_3dPoint&);
682  ON_3fVector& operator=(const ON_4dPoint&);
683  ON_3fVector& operator=(const ON_2dVector&);
684  ON_3fVector& operator=(const ON_3dVector&);
685  ON_3fVector& operator=(const double*); // point = double[3] support
686
687  ON_3fVector operator-() const;
688
689  ON_3fVector& operator*=(float);
690  ON_3fVector& operator/=(float);
691  ON_3fVector& operator+=(const ON_3fVector&);
692  ON_3fVector& operator-=(const ON_3fVector&);
693
694  float operator*(const ON_3fVector&) const; // inner (dot) product
695  float operator*(const ON_3fPoint&) const; // inner (dot) product (point acting as a vector)
696  double operator*(const ON_3dVector&) const; // inner (dot) product
697
698  ON_3fVector operator*(int) const;
699  ON_3fVector operator/(int) const;
700  ON_3fVector operator*(float) const;
701  ON_3fVector operator/(float) const;
702  ON_3dVector operator*(double) const;
703  ON_3dVector operator/(double) const;
704
705  ON_3fVector operator+(const ON_3fVector&) const;
706  ON_3fPoint operator+(const ON_3fPoint&) const;
707  ON_3fVector operator-(const ON_3fVector&) const;
708  ON_3fPoint operator-(const ON_3fPoint&) const;
709  ON_3fVector operator+(const ON_2fVector&) const;
710  ON_3fPoint operator+(const ON_2fPoint&) const;
711  ON_3fVector operator-(const ON_2fVector&) const;
712  ON_3fPoint operator-(const ON_2fPoint&) const;
713
714  ON_3dVector operator+(const ON_3dVector&) const;
715  ON_3dPoint operator+(const ON_3dPoint&) const;
716  ON_3dVector operator-(const ON_3dVector&) const;
717  ON_3dPoint operator-(const ON_3dPoint&) const;
718  ON_3dVector operator+(const ON_2dVector&) const;
719  ON_3dPoint operator+(const ON_2dPoint&) const;
720  ON_3dVector operator-(const ON_2dVector&) const;
721  ON_3dPoint operator-(const ON_2dPoint&) const;
722
723  float operator*(const ON_4fPoint&) const;
724
725  bool operator==(const ON_3fVector&) const;
726  bool operator!=(const ON_3fVector&) const;
727
728  // dictionary order comparisons
729  bool operator<=(const ON_3fVector&) const;
730  bool operator>=(const ON_3fVector&) const;
731  bool operator<(const ON_3fVector&) const;
732  bool operator>(const ON_3fVector&) const;
733
734  // index operators mimic float[3] behavior
735  float& operator[](int);
736  float operator[](int) const;
737  float& operator[](unsigned int);
738  float operator[](unsigned int) const;
739
740  // set 3d vector value
741  void Set(float,float,float);
742
743  int MaximumCoordinateIndex() const;
744  double MaximumCoordinate() const; // absolute value of maximum coordinate
745
746  double LengthSquared() const;
747  double Length() const;
748
749  bool IsPerpendicularTo(
750  // returns true: this and other vectors are perpendicular
751  // false: this and other vectors are not perpendicular
752  // or at least one of the vectors is zero
753  const ON_3fVector&, // other vector
754  double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
755  ) const;
756
757  double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d vectors
758
759  void Zero(); // set all coordinates to zero
760  void Reverse(); // negate all coordinates
761  bool Unitize(); // returns false if vector has zero length
762  bool IsUnitVector() const;
763
764  // Description:
765  // Test a vector to see if it is very short
766  //
767  // Parameters:
768  // tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero
769  // value used as the coordinate zero tolerance.
770  //
771  // Returns:
772  // ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol && fabs(z) <= tiny_tol )
773  //
774  bool IsTiny(
775  double = ON_ZERO_TOLERANCE // tiny_tol
776  ) const;
777
778  // Returns:
779  // true if vector is the zero vector.
780  bool IsZero() const;
781
782  // set this vector to be perpendicular to another vector
783  bool PerpendicularTo( // Result is not unitized.
784  // returns false if input vector is zero
785  const ON_3fVector&
786  );
787
788  // These transform the vector in place. The transformation matrix acts on
789  // the left of the vector; i.e., result = transformation*vector
790  void Transform(
791  const ON_Xform& // can use ON_Xform here
792  );
793
794  void Rotate(
795  double, // angle in radians
796  const ON_3fVector& // axis of rotation
797  );
798
799  void Rotate(
800  double, // sin(angle)
801  double, // cos(angle)
802  const ON_3fVector& // axis of rotation
803  );
804 };
805
806 ON_DECL
807 ON_3fVector operator*(int, const ON_3fVector&);
808
809 ON_DECL
810 ON_3fVector operator*(float, const ON_3fVector&);
811
812 ON_DECL
813 ON_3dVector operator*(double, const ON_3fVector&);
814
815 ///////////////////////////////////////////////////////////////
816 //
817 // ON_3fVector utilities
818 //
819
820 ON_DECL
821 float
822 ON_DotProduct(
823  const ON_3fVector&,
824  const ON_3fVector&
825  );
826
827
828 ON_DECL
830 ON_CrossProduct(
831  const ON_3fVector&,
832  const ON_3fVector&
833  );
834
835 ON_DECL
837 ON_CrossProduct( // 3d cross product for old fashioned arrays
838  const float*, // array of 3d floats
839  const float* // array of 3d floats
840  );
841
842 ON_DECL
843 float
844 ON_TripleProduct(
845  const ON_3fVector&,
846  const ON_3fVector&,
847  const ON_3fVector&
848  );
849
850 ON_DECL
851 float
852 ON_TripleProduct( // 3d triple product for old fashioned arrays
853  const float*, // array of 3d floats
854  const float*, // array of 3d floats
855  const float* // array of 3d floats
856  );
857
858 ON_DECL
859 bool
860 ON_IsOrthogonalFrame( // true if X, Y, Z are nonzero and mutually perpendicular
861  const ON_3fVector&, // X
862  const ON_3fVector&, // Y
863  const ON_3fVector& // Z
864  );
865
866 ON_DECL
867 bool
868 ON_IsOrthonormalFrame( // true if X, Y, Z are orthogonal and unit length
869  const ON_3fVector&, // X
870  const ON_3fVector&, // Y
871  const ON_3fVector& // Z
872  );
873
874 ON_DECL
875 bool
876 ON_IsRightHandFrame( // true if X, Y, Z are orthonormal and right handed
877  const ON_3fVector&, // X
878  const ON_3fVector&, // Y
879  const ON_3fVector& // Z
880  );
881
882 ///////////////////////////////////////////////////////////////
883 //
884 // common points and vectors
885 //
886
887 // ON_forigin is OBSOLETE - use ON_3fPoint::Origin
888 extern ON_EXTERN_DECL const ON_3fPoint ON_forigin; // (0.0, 0.0, 0.0)
889
890 // ON_fxaxis is OBSOLETE - use ON_3fPoint::XAxis
891 extern ON_EXTERN_DECL const ON_3fVector ON_fxaxis; // (1.0, 0.0, 0.0)
892
893 // ON_fyaxis is OBSOLETE - use ON_3fVector::YAxis
894 extern ON_EXTERN_DECL const ON_3fVector ON_fyaxis; // (0.0, 1.0, 0.0)
895
896 // ON_fzaxis is OBSOLETE - use ON_3fVector::ZAxis
897 extern ON_EXTERN_DECL const ON_3fVector ON_fzaxis; // (0.0, 0.0, 1.0)
898
899
900 #endif
static const ON_3fVector YAxis
static const ON_2fPoint Origin
static const ON_2fVector ZeroVector
static const ON_2fVector YAxis
static const ON_3fPoint Origin
static const ON_3fVector ZAxis
static const ON_3fVector ZeroVector
static const ON_2fVector XAxis
static const ON_3fVector XAxis