-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry_linux.cpp
More file actions
9490 lines (7929 loc) · 192 KB
/
Copy pathGeometry_linux.cpp
File metadata and controls
9490 lines (7929 loc) · 192 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "Main.h"
#include "Geometry_linux.h"
#include "PixelBuffer_linux.h"
// The following are class member definitions for coordinate points.
#define EPSILON 0.0000001
int MulDiv ( int m1, int m2, int d ) { return m1*m2/d; }
CRect::CRect()
{
top = 0;
bottom = 0;
left = 0;
right = 0;
}
CRect::operator LPRECT()
{
return this;
}
void CColorCoord::Offset(DOUBLE x, DOUBLE y, DOUBLE z)
{
m_x += x ;
m_y += y ;
m_z += z ;
}
// Move the point a distance in the direction of slope
void CColorCoord::Offset(CVector &slope, DOUBLE distance)
{
// The slopes are normalized!
m_x += distance * slope.m_dx ;
m_y += distance * slope.m_dy ;
m_z += distance * slope.m_dz ;
}
CColorCoord &CColorCoord::Rotate(CQuaternion &qtemp, bool Reverse)
{
CQuaternion q = qtemp ;
if (Reverse)
q.m_w = -q.m_w ;
*this = q ^ *this ^ ~q ;
if (Reverse)
q.m_w = -q.m_w ;
return *this;
}
CColorCoord &CColorCoord::Rotate(CQuaternion &q, CQuaternion &qInv, bool Reverse)
{
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
*this = q ^ *this ^ qInv ;
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
return *this;
}
CColorCoord::CColorCoord()
{
m_r = m_g = m_b = m_x = m_y = m_z = m_d = 0.0 ;
}
CColorCoord::CColorCoord (DOUBLE x, DOUBLE y, DOUBLE z, DOUBLE r, DOUBLE g, DOUBLE b)
{
m_x = x ;
m_y = y ;
m_z = z ;
m_r = r ;
m_g = g ;
m_b = b ;
}
CColorCoord::CColorCoord (const CColorCoord ©)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_r = copy.m_r ;
m_g = copy.m_g ;
m_b = copy.m_b ;
m_d = copy.m_d ;
}
CColorCoord::CColorCoord (const CCoord ©)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_r = 0.0 ;
m_g = 0.0 ;
m_b = 0.0 ;
m_d = 0.0 ;
}
void CColorCoord::Clear()
{
m_x = m_y = m_z = 0.0 ;
m_r = m_g = m_b = 0.0 ;
m_d = 0.0 ;
}
CColorCoord& CColorCoord::operator=(const CColorCoord& copy)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_r = copy.m_r ;
m_g = copy.m_g ;
m_b = copy.m_b ;
m_d = copy.m_d ;
return *this;
}
CColorCoord& CColorCoord::operator=(const CQuaternion& copy)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
return *this;
}
CColorCoord& CColorCoord::operator=(const CCoord& copy)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
return *this;
}
CCoord::CCoord()
{
m_x = m_y = m_z = 0.0 ;
m_sx = m_sy = 0;
m_nData = 255 ;
}
CCoord::CCoord(const CPoint &pt)
{
m_x = (DOUBLE)pt.x ;
m_y = (DOUBLE)pt.y ;
m_z = 0.0 ;
m_sx = m_sy = 0;
m_nData = 255 ;
}
DOUBLE CCoord::Angle(const CCoord &one, const CCoord &two)
{
CVector dirone(*this, one) ;
CVector dirtwo(*this, two) ;
DOUBLE angle ;
dirone.Normalize() ;
dirtwo.Normalize() ;
angle = (DOUBLE) (acos ( (DOUBLE) dirone.DotProduct(dirtwo) ) * RAD_TO_DEG) ;
return angle ;
}
DOUBLE CCoord::Angle2D(const CCoord &one, const CCoord &two)
{
CVector dirone(*this, one) ;
CVector dirtwo(*this, two) ;
DOUBLE angle ;
dirone.Normalize() ;
dirtwo.Normalize() ;
angle = (DOUBLE) (atan2 ( (DOUBLE) dirone.PerpDotProduct2D(dirtwo), (DOUBLE) dirone.DotProduct2D(dirtwo) ) * RAD_TO_DEG );
return angle ;
}
DOUBLE CCoord::Angle2D(const CCoord &one)
{
CVector dirone(*this, one) ;
CVector dirtwo(1,0,0) ;
DOUBLE angle ;
dirone.Normalize() ;
dirtwo.Normalize() ;
angle = (DOUBLE) (atan2 ( (DOUBLE) dirone.PerpDotProduct2D(dirtwo), (DOUBLE) dirone.DotProduct2D(dirtwo) ) * RAD_TO_DEG );
return angle ;
}
DOUBLE CCoord::DotProduct (CVector &slope)
{
return slope.m_dx*m_x + slope.m_dy*m_y + slope.m_dz * m_z;
}
DOUBLE CCoord::DotProduct (CCoord &slope)
{
return slope.m_x*m_x + slope.m_y*m_y + slope.m_z * m_z;
}
DOUBLE CCoord::DotProduct2D (CVector &slope)
{
return slope.m_dx*m_x + slope.m_dy*m_y ;
}
DOUBLE CCoord::DotProduct2D (CCoord &slope)
{
return slope.m_x*m_x + slope.m_y*m_y ;
}
DOUBLE CCoord::PerpDotProduct2D (CVector &slope)
{
return slope.m_dy*m_x - slope.m_dx*m_y ;
}
DOUBLE CCoord::PerpDotProduct2D (CCoord &slope)
{
return slope.m_y*m_x - slope.m_x*m_y ;
}
int CCoord::ScreenDistSqr(CPoint &p)
{
int rval ;
int dx ;
int dy ;
dx = p.x - m_sx ;
dy = p.y - m_sy ;
rval = dx*dx + dy*dy ;
return rval ;
}
bool CCoord::IsEmpty()
{
if (m_x==0.0 && m_y==0.0 && m_z==0.0)
return true ;
else
return false ;
}
CCoord::CCoord (DOUBLE x, DOUBLE y, DOUBLE z)
{
m_x = x ;
m_y = y ;
m_z = z ;
m_nData = 255 ;
}
CPoint CCoord::MakePoint()
{
return CPoint((int)m_x, (int)m_y) ;
}
CCoord::CCoord (DOUBLE *comp, int numcomp)
{
switch (numcomp)
{
case 2:
m_x = comp[0] ;
m_y = comp[1] ;
m_z = 0 ;
break;
case 3:
m_x = comp[0] ;
m_y = comp[1] ;
m_z = comp[2] ;
break;
default:
m_x = m_y = m_z = 0.0 ;
break;
}
}
CCoord::CCoord (const CCoord ©)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_sx = copy.m_sx ;
m_sy = copy.m_sy ;
m_nData = copy.m_nData ;
}
void CCoord::Clear()
{
m_x = m_y = m_z = 0.0 ;
m_nData = 255 ;
}
CCoord::CCoord(const CVector& copy)
{
m_x = copy.m_dx ;
m_y = copy.m_dy ;
m_z = copy.m_dz ;
m_nData = 255 ;
}
void CCoord::Round(DOUBLE precision)
{
m_x = (DOUBLE)floor(m_x / precision + (DOUBLE)0.5) * precision ;
m_y = (DOUBLE)floor(m_y / precision + (DOUBLE)0.5) * precision ;
m_z = (DOUBLE)floor(m_z / precision + (DOUBLE)0.5) * precision ;
if (fabs(m_x) < precision)
m_x = 0 ;
if (fabs(m_y) < precision)
m_y = 0 ;
if (fabs(m_z) < precision)
m_z = 0 ;
}
void CCoord::Set(DOUBLE x, DOUBLE y, DOUBLE z, long nVal)
{
m_x = x ;
m_y = y ;
m_z = z ;
m_nData = nVal ;
}
void CCoord::Set(DOUBLE *comp, int numcomp)
{
unsigned char *ucomp = (unsigned char *)(comp + 3);
switch (numcomp)
{
case 2:
m_x = comp[0] ;
m_y = comp[1] ;
m_z = 0 ;
break;
case 3:
m_x = comp[0] ;
m_y = comp[1] ;
m_z = comp[2] ;
break;
case 4:
m_x = comp[0] ;
m_y = comp[1] ;
m_z = comp[2] ;
m_nData = ucomp[0] ;
break;
default:
m_x = m_y = m_z = 0.0 ;
break;
}
}
//void AFXAPI ConstructElements (CCoord*, int)
//{
//}
void CCoord::ToPoint(LPPOINT lppt)
{
lppt->x = (int)floor(m_x + 0.5) ;
lppt->y = (int)floor(m_y + 0.5) ;
}
CCoord& CCoord::operator=(const CCoord& copy)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_nData = copy.m_nData ;
m_sx = copy.m_sx ;
m_sy = copy.m_sy ;
return *this;
}
CCoord& CCoord::operator=(const CQuaternion& copy)
{
m_x = copy.m_x ;
m_y = copy.m_y ;
m_z = copy.m_z ;
m_nData = 255 ;
return *this;
}
void CCoord::Offset(DOUBLE x, DOUBLE y, DOUBLE z)
{
m_x += x ;
m_y += y ;
m_z += z ;
}
// Move the point a distance in the direction of slope
void CCoord::Offset(CVector &slope, DOUBLE distance)
{
// The slopes are normalized!
m_x += distance * slope.m_dx ;
m_y += distance * slope.m_dy ;
m_z += distance * slope.m_dz ;
}
CCoord::operator CVector ()
{
return CVector(m_x, m_y, m_z);
}
CCoord::operator CPoint ()
{
return CPoint((int)m_x, (int)m_y);
}
bool CCoord::operator==(CCoord &comp) const
{
return ((comp.m_x == m_x) && (comp.m_y == m_y) && (comp.m_z == m_z)) ;
}
bool CCoord::operator==(CVector &comp) const
{
return ((comp.m_dx == m_x) && (comp.m_dy == m_y) && (comp.m_dz == m_z)) ;
}
bool CCoord::operator!=(CCoord &comp) const
{
return ((comp.m_x != m_x) || (comp.m_y != m_y) || (comp.m_z != m_z)) ;
}
void CCoord::operator+=(const CCoord &add)
{
m_x += add.m_x ;
m_y += add.m_y ;
m_z += add.m_z ;
}
void CCoord::operator+=(const CVector &add)
{
m_x += add.m_dx ;
m_y += add.m_dy ;
m_z += add.m_dz ;
}
void CCoord::operator-=(const CCoord &minus)
{
m_x -= minus.m_x ;
m_y -= minus.m_y ;
m_z -= minus.m_z ;
}
void CCoord::operator-=(const CVector &minus)
{
m_x -= minus.m_dx ;
m_y -= minus.m_dy ;
m_z -= minus.m_dz ;
}
CCoord CCoord::operator+(const CCoord &add) const
{
return CCoord(m_x+add.m_x, m_y+add.m_y, m_z+add.m_z) ;
}
CCoord CCoord::operator+(const CVector &add) const
{
return CCoord(m_x + add.m_dx, m_y + add.m_dy, m_z + add.m_dz) ;
}
CCoord CCoord::operator-(const CCoord &minus) const
{
return CCoord(m_x - minus.m_x, m_y - minus.m_y, m_z - minus.m_z) ;
}
CCoord CCoord::Average(CCoord &pt)
{
return CCoord((m_x+pt.m_x)/(DOUBLE)2.0, (m_y+pt.m_y)/(DOUBLE)2.0, (m_z+pt.m_z)/(DOUBLE)2.0) ;
}
CCoord CCoord::operator-(const CVector &minus) const
{
return CCoord(m_x - minus.m_dx, m_y - minus.m_dy, m_z - minus.m_dz) ;
}
CCoord CCoord::operator *(DOUBLE Magnitude)
{
return CCoord(m_x * Magnitude, m_y * Magnitude, m_z * Magnitude) ;
}
CCoord CCoord::operator/(DOUBLE Magnitude)
{
return CCoord(m_x / Magnitude, m_y / Magnitude, m_z / Magnitude) ;
}
CCoord CCoord::operator-()
{
return CCoord(-m_x, -m_y, -m_z);
}
DOUBLE CCoord::Distance (const CCoord &second)
{
DOUBLE dx, dy, dz ;
dx = second.m_x - m_x ;
dy = second.m_y - m_y ;
dz = second.m_z - m_z ;
return (DOUBLE)sqrt (dx*dx + dy*dy + dz*dz) ;
}
DOUBLE *CCoord::GetVal()
{
return &m_x ;
}
void CCoord::Trace()
{
#ifdef _DEBUG
#ifndef _tracer_dll_h
// ,m_x, m_y, m_z) ;
#endif
#endif
}
bool CQuaternion::Rotate(DOUBLE *pvec, int nNumElem, int nStepSize, bool bReverse)
{
CQuaternion q ;
CCoord c ;
int i ;
for (i=0; i<nNumElem; i++,pvec+=nStepSize)
{
if (bReverse)
m_w = -m_w ;
c = *this ^ pvec ^ ~(*this) ;
if (bReverse)
m_w = -m_w ;
pvec[0] = c.m_x ;
pvec[1] = c.m_y ;
pvec[2] = c.m_z ;
}
return true ;
}
CCoord &CCoord::Rotate(CQuaternion &q, bool Reverse)
{
if (Reverse)
q.m_w = -q.m_w ;
*this = q ^ *this ^ ~q ;
if (Reverse)
q.m_w = -q.m_w ;
return *this;
}
CCoord &CCoord::Rotate(CQuaternion &q, CQuaternion &qInv, bool Reverse)
{
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
*this = q ^ *this ^ qInv ;
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
return *this;
}
// The following are class member definitions for slopes
CVector::CVector()
{
m_dx = m_dy = m_dz = 0.0 ;
}
CVector::CVector(DOUBLE dx, DOUBLE dy, DOUBLE dz)
{
m_dx = dx ;
m_dy = dy ;
m_dz = dz ;
}
CVector::CVector(DOUBLE *deltas)
{
m_dx = deltas[0] ;
m_dy = deltas[1] ;
m_dz = deltas[2] ;
}
void CVector::Invert()
{
m_dx = -m_dx ;
m_dy = -m_dy ;
m_dz = -m_dz ;
}
CVector::CVector(const CVector ©)
{
m_dx = copy.m_dx ;
m_dy = copy.m_dy ;
m_dz = copy.m_dz ;
}
CVector::CVector(const CCoord ©)
{
m_dx = copy.m_x ;
m_dy = copy.m_y ;
m_dz = copy.m_z ;
}
CVector::CVector(DOUBLE x1, DOUBLE y1, DOUBLE z1, DOUBLE x2, DOUBLE y2, DOUBLE z2)
{
m_dx = x2 - x1 ;
m_dy = y2 - y1 ;
m_dz = z2 - z1 ;
}
CVector::CVector(CLine ©)
{
CVector v = copy.Slope();
*this = v;
}
CVector::CVector(const CCoord &c1, const CCoord &c2, bool Normalize/*=true*/)
{
Set(c1, c2, Normalize) ;
}
CVector & CVector::operator=(const CVector& copy)
{
m_dx = copy.m_dx ;
m_dy = copy.m_dy ;
m_dz = copy.m_dz ;
return *this;
}
CVector& CVector::operator=(const CQuaternion& copy)
{
m_dx = copy.m_x ;
m_dy = copy.m_y ;
m_dz = copy.m_z ;
return *this;
}
// This method simply scales the vector components to the
// desired magnitude. If you want a vector with the same
// length as magnitude, you must first, normalize the
// vector.
CVector CVector::operator *(DOUBLE Magnitude)
{
return CVector(m_dx * Magnitude, m_dy * Magnitude, m_dz * Magnitude) ;
}
CVector CVector::operator/(DOUBLE Magnitude)
{
return CVector(m_dx / Magnitude, m_dy / Magnitude, m_dz / Magnitude) ;
}
DOUBLE CVector::Magnitude()
{
return (DOUBLE)sqrt(m_dx*m_dx + m_dy*m_dy + m_dz*m_dz) ;
}
// Using the delta version causes normalizatoin to occur
void CVector::Set(DOUBLE dx, DOUBLE dy, DOUBLE dz)
{
m_dx = dx ;
m_dy = dy ;
m_dz = dz ;
Normalize() ;
}
void CVector::Set(const CVector ©)
{
*this = copy ;
}
// Using the coordinate version does not cause normalizatoin to occur
void CVector::Set(DOUBLE x1, DOUBLE y1, DOUBLE z1, DOUBLE x2, DOUBLE y2, DOUBLE z2)
{
m_dx = x2 - x1 ;
m_dy = y2 - y1 ;
m_dz = z2 - z1 ;
}
void CVector::Set(CLine ©)
{
Set(copy.Slope()) ;
}
// Using the coordinate version does not cause normalizatoin to occur
void CVector::Set(const CCoord &c1, const CCoord &c2, bool bNormalize/*=true*/)
{
m_dx = c2.m_x - c1.m_x ;
m_dy = c2.m_y - c1.m_y ;
m_dz = c2.m_z - c1.m_z ;
if (bNormalize)
Normalize() ;
}
void CVector::SetNormal2D(const CCoord &c1, const CCoord &c2, bool bNormalize/*=true*/)
{
m_dx = c1.m_y - c2.m_y ;
m_dy = c2.m_x - c1.m_x ;
m_dz = 0 ;
//if (bNormalize)
Normalize() ;
}
void CVector::Set(DOUBLE *comp, int numcomp)
{
switch (numcomp)
{
case 2:
m_dx = comp[0] ;
m_dy = comp[1] ;
m_dz = 0 ;
break;
case 3:
m_dx = comp[0] ;
m_dy = comp[1] ;
m_dz = comp[2] ;
break;
default:
m_dx = m_dy = m_dz = 0.0 ;
break;
}
}
void CVector::Clear()
{
m_dx = m_dy = m_dz = 0.0 ;
}
void CVector::Normalize()
{
DOUBLE d ;
d = (DOUBLE)sqrt(m_dx*m_dx + m_dy*m_dy + m_dz*m_dz) ;
if (d != (DOUBLE)0.0)
{
m_dx = m_dx / d ;
m_dy = m_dy / d ;
m_dz = m_dz / d ;
}
}
CVector &CVector::operator=(CLine& copy)
{
*this = copy.Slope();
return *this;
}
CVector &CVector::operator=(const CCoord& copy)
{
m_dx = copy.m_x ;
m_dy = copy.m_y ;
m_dz = copy.m_z ;
return *this;
}
bool CVector::operator==(CVector &comp) const
{
/*
if (comp.IsVertical() && IsVertical())
return true ;
return (m_dy/m_dx == comp.m_dy/comp.m_dx) ;
*/
// assume we're normalized
if ( comp.m_dx == m_dx
&& comp.m_dy == m_dy
&& comp.m_dz == m_dz
)
return true ;
else
return false ;
}
bool CVector::IsDefined()
{
return (m_dx != 0.0) ;
}
bool CVector::IsVertical()
{
return (m_dx == 0.0) ;
}
CVector::operator DOUBLE()
{
return m_dy / m_dx ;
}
// Since our slopes are normalized when they are
// set, our dot product will always have a length
// of 1 (i.e. dx^2 + dy^2 = 1). The return value
// is cos(x) of the angle between slope 1 and
// slope 2
DOUBLE CVector::DotProduct (const CVector &slope)
{
return slope.m_dx*m_dx + slope.m_dy*m_dy + slope.m_dz * m_dz;
}
DOUBLE CVector::DotProduct (CCoord &slope)
{
return slope.m_x*m_dx + slope.m_y*m_dy + slope.m_z * m_dz;
}
DOUBLE CVector::DotProduct2D (CVector &slope)
{
return slope.m_dx*m_dx + slope.m_dy*m_dy ;
}
DOUBLE CVector::DotProduct2D (CCoord &slope)
{
return slope.m_x*m_dx + slope.m_y*m_dy ;
}
DOUBLE CVector::PerpDotProduct2D (CVector &slope)
{
return slope.m_dy*m_dx - slope.m_dx*m_dy ;
}
DOUBLE CVector::PerpDotProduct2D (CCoord &slope)
{
return slope.m_y*m_dx - slope.m_x*m_dy ;
}
bool CVector::CrossProduct (const CVector &a, const CVector &b, bool Normalize)
{
DOUBLE length ;
// First, calculate the vector components
m_dx = a.m_dy * b.m_dz - a.m_dz * b.m_dy ;
m_dy = a.m_dz * b.m_dx - a.m_dx * b.m_dz ;
m_dz = a.m_dx * b.m_dy - a.m_dy * b.m_dx ;
// Next, normalize the components
if (Normalize)
{
if (m_dx!=0.0 || m_dy!=0.0 || m_dz!=0.0)
{
length = (DOUBLE)sqrt(m_dx*m_dx + m_dy*m_dy + m_dz*m_dz);
m_dx /= length ;
m_dy /= length ;
m_dz /= length ;
}
else
return false ;
}
return true ;
}
DOUBLE *CVector::GetVal()
{
return &m_dx;
}
CVector & CVector::operator+(const CVector &addend)
{
m_dx += addend.m_dx ;
m_dy += addend.m_dy ;
m_dz += addend.m_dz ;
return *this ;
}
CVector & CVector::operator-(const CVector &diffend)
{
m_dx -= diffend.m_dx ;
m_dy -= diffend.m_dy ;
m_dz -= diffend.m_dz ;
return *this ;
}
CVector CVector::operator-()
{
CVector rval ;
rval.m_dx = -m_dx ;
rval.m_dy = -m_dy ;
rval.m_dz = -m_dz ;
return rval ;
}
void CVector::operator+=(const CVector &addend)
{
m_dx += addend.m_dx ;
m_dy += addend.m_dy ;
m_dz += addend.m_dz ;
}
void CVector::operator*=(DOUBLE Magnitude)
{
m_dx *= Magnitude;
m_dy *= Magnitude;
m_dz *= Magnitude;
}
void CCoord::operator*=(DOUBLE Magnitude)
{
m_x *= Magnitude;
m_y *= Magnitude;
m_z *= Magnitude;
}
void CCoord::operator/=(DOUBLE Magnitude)
{
m_x /= Magnitude;
m_y /= Magnitude;
m_z /= Magnitude;
}
void CVector::operator-=(const CVector &diffend)
{
m_dx -= diffend.m_dx ;
m_dy -= diffend.m_dy ;
m_dz -= diffend.m_dz ;
}
void CVector::Trace()
{
#ifdef _DEBUG
#ifndef _tracer_dll_h
// ,m_dx, m_dy, m_dz) ;
#endif
#endif
}
CVector &CVector::Rotate(CQuaternion &q, bool Reverse)
{
if (Reverse)
q.m_w = -q.m_w ;
*this = q ^ *this ^ ~q ;
if (Reverse)
q.m_w = -q.m_w ;
return *this;
}
CVector &CVector::Rotate(CQuaternion &q, CQuaternion &qInv, bool Reverse)
{
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
*this = q ^ *this ^ qInv ;
if (Reverse)
{
q.m_w = -q.m_w ;
qInv.m_w = -qInv.m_w ;
}
return *this;
}
// The following are class member definitions for lines
CLine::CLine ()
{
m_pPrevious = NULL ;
Set(0,0,0,0,0,0) ;
}