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