-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathTSConformal2D.h
1104 lines (834 loc) · 29.5 KB
/
TSConformal2D.h
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
//
// This file is part of the Terathon Math Library, by Eric Lengyel.
// Copyright 1999-2024, Terathon Software LLC
//
// This software is distributed under the MIT License.
// Separate proprietary licenses are available from Terathon Software.
//
#ifndef TSConformal2D_h
#define TSConformal2D_h
#include "TSRigid2D.h"
#define TERATHON_ROUNDPOINT2D 1
#define TERATHON_DIPOLE2D 1
#define TERATHON_CIRCLE2D 1
namespace Terathon
{
struct ConstRoundPoint2D;
struct ConstDipole2D;
struct ConstCircle2D;
// ==============================================
// RoundPoint2D
// ==============================================
/// @brief Encapsulates a 2D round point in conformal geometric algebra.
///
/// The \c RoundPoint2D class is used to store a two-dimensional round point with a four-dimensional vector representation in conformal geometric algebra.
///
/// @sa Dipole2D
/// @sa Circle2D
class RoundPoint2D
{
public:
float x, y, z, w;
TERATHON_API static const ConstRoundPoint2D zero;
/// @brief Default constructor that leaves the components uninitialized.
inline RoundPoint2D() = default;
/// @brief Constructor that sets components explicitly.
/// @param ax,ay,az,aw The components of the round point.
RoundPoint2D(float ax, float ay, float az, float aw)
{
x = ax;
y = ay;
z = az;
w = aw;
}
/// @brief Constructor that converts a Euclidean point to a round point.
/// @param p The Euclidean point to convert. The \e z component of the round point is set to 1.0, and the \e w component is set to (<i>x</i><sup>2</sup> + <i>y</i><sup>2</sup>) / 2.
RoundPoint2D(const Point2D& p)
{
x = p.x;
y = p.y;
z = 1.0F;
w = (p.x * p.x + p.y * p.y) * 0.5F;
}
/// @brief Sets all five components of a 2D round point.
/// @param ax,ay,az,aw The new components of the round point.
RoundPoint2D& Set(float ax, float ay, float az, float aw)
{
x = ax;
y = ay;
z = az;
w = aw;
return (*this);
}
void Set(float ax, float ay, float az, float aw) volatile
{
x = ax;
y = ay;
z = az;
w = aw;
}
/// @brief Returns a reference to a scalar component of a 2D round point.
/// @param k The index of the component. Must be 0, 1, 2, or 3.
float& operator [](machine k)
{
return ((&x)[k]);
}
const float& operator [](machine k) const
{
return ((&x)[k]);
}
RoundPoint2D& operator *=(float n)
{
x *= n;
y *= n;
z *= n;
w *= n;
return (*this);
}
RoundPoint2D& operator /=(float n)
{
n = 1.0F / n;
x *= n;
y *= n;
z *= n;
w *= n;
return (*this);
}
RoundPoint2D& Unitize(void)
{
float n = 1.0F / z;
x *= n;
y *= n;
w *= n;
z = 1.0F;
return (*this);
}
};
/// @brief Returns the negation of the 2D round point \c a.
/// @related RoundPoint2D
inline RoundPoint2D operator -(const RoundPoint2D& a)
{
return (RoundPoint2D(-a.x, -a.y, -a.z, -a.w));
}
/// @brief Returns the product of the 2D round point \c a and the scalar \c n.
/// @related RoundPoint2D
inline RoundPoint2D operator *(const RoundPoint2D& a, float n)
{
return (RoundPoint2D(a.x * n, a.y * n, a.z * n, a.w * n));
}
/// @brief Returns the product of the 2D round point \c a and the scalar \c n.
/// @related RoundPoint2D
inline RoundPoint2D operator *(float n, const RoundPoint2D& a)
{
return (RoundPoint2D(n * a.x, n * a.y, n * a.z, n * a.w));
}
/// @brief Returns the product of the 2D round point \c a and the inverse of the scalar \c n.
/// @related RoundPoint2D
inline RoundPoint2D operator /(const RoundPoint2D& a, float n)
{
n = 1.0F / n;
return (RoundPoint2D(a.x * n, a.y * n, a.z * n, a.w * n));
}
/// @brief Returns a boolean value indicating whether the two 2D round points \c a and \c b are equal.
/// @related RoundPoint2D
inline bool operator ==(const RoundPoint2D& a, const RoundPoint2D& b)
{
return ((a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w));
}
/// @brief Returns a boolean value indicating whether the two 2D round points \c a and \c b are not equal.
/// @related RoundPoint2D
inline bool operator !=(const RoundPoint2D& a, const RoundPoint2D& b)
{
return ((a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w));
}
// ==============================================
// Dipole2D
// ==============================================
/// @brief Encapsulates a 2D dipole in conformal geometric algebra.
///
/// The \c Dipole2D class is used to store a two-dimensional dipole with a four-dimensional bivector representation in conformal geometric algebra.
///
/// @sa RoundPoint2D
/// @sa Circle2D
class Dipole2D
{
public:
Line2D g;
FlatPoint2D p;
TERATHON_API static const ConstDipole2D zero;
/// @brief Default constructor that leaves the components uninitialized.
inline Dipole2D() = default;
/// @brief Constructor that sets components explicitly.
/// @param gx,gy,gz The components of the dipole corresponding to the <b>e</b><sub>23</sub>, <b>e</b><sub>31</sub>, and <b>e</b><sub>12</sub> basis elements.
/// @param px,py,pz The components of the dipole corresponding to the <b>e</b><sub>41</sub>, <b>e</b><sub>42</sub>, and <b>e</b><sub>43</sub> basis elements.
Dipole2D(float gx, float gy, float gz, float px, float py, float pz)
{
g.Set(gx, gy, gz);
p.Set(px, py, pz);
}
/// @brief Constructor that sets components explicitly.
/// @param line The carrier line.
/// @param point The flat point component.
Dipole2D(const Line2D& line, const FlatPoint2D& point)
{
g = line;
p = point;
}
/// @brief Sets all six components of a 2D dipole.
/// @param gx,gy,gz The components of the dipole corresponding to the <b>e</b><sub>23</sub>, <b>e</b><sub>31</sub>, and <b>e</b><sub>12</sub> basis elements.
/// @param px,py,pz The components of the dipole corresponding to the <b>e</b><sub>41</sub>, <b>e</b><sub>42</sub>, and <b>e</b><sub>43</sub> basis elements.
Dipole2D& Set(float gx, float gy, float gz, float px, float py, float pz)
{
g.Set(gx, gy, gz);
p.Set(px, py, pz);
return (*this);
}
void Set(float gx, float gy, float gz, float px, float py, float pz) volatile
{
g.Set(gx, gy, gz);
p.Set(px, py, pz);
}
/// @brief Sets all ten components of a 2D dipole.
/// @param line The carrier line.
/// @param point The flat point component.
Dipole2D& Set(const Line2D& line, const FlatPoint2D& point)
{
g = line;
p = point;
return (*this);
}
void Set(const Line2D& line, const FlatPoint2D& point) volatile
{
g = line;
p = point;
}
Dipole2D& operator *=(float n)
{
g *= n;
p *= n;
return (*this);
}
Dipole2D& operator /=(float n)
{
n = 1.0F / n;
g *= n;
p *= n;
return (*this);
}
Dipole2D& Unitize(void)
{
return (*this *= InverseSqrt(g.x * g.x + g.y * g.y));
}
};
/// @brief Returns the negation of the 2D dipole \c d.
/// @related Dipole2D
inline Dipole2D operator -(const Dipole2D& d)
{
return (Dipole2D(-d.g.x, -d.g.y, -d.g.z, -d.p.x, -d.p.y, -d.p.z));
}
/// @brief Returns the product of the 2D dipole \c d and the scalar \c n.
/// @related Dipole2D
inline Dipole2D operator *(const Dipole2D& d, float n)
{
return (Dipole2D(d.g.x * n, d.g.y * n, d.g.z * n, d.p.x * n, d.p.y * n, d.p.z * n));
}
/// @brief Returns the product of the 2D dipole \c d and the scalar \c n.
/// @related Dipole2D
inline Dipole2D operator *(float n, const Dipole2D& d)
{
return (Dipole2D(n * d.g.x, n * d.g.y, n * d.g.z, n * d.p.x, n * d.p.y, n * d.p.z));
}
/// @brief Returns the product of the 2D dipole \c d and the inverse of the scalar \c n.
/// @related Dipole2D
inline Dipole2D operator /(const Dipole2D& d, float n)
{
n = 1.0F / n;
return (Dipole2D(d.g.x * n, d.g.y * n, d.g.z * n, d.p.x * n, d.p.y * n, d.p.z * n));
}
/// @brief Returns a boolean value indicating whether the two 2D dipoles \c d and \c f are equal.
/// @related Dipole2D
inline bool operator ==(const Dipole2D& d, const Dipole2D& f)
{
return ((d.g == f.g) && (d.p == f.p));
}
/// @brief Returns a boolean value indicating whether the two 2D dipoles \c d and \c f are not equal.
/// @related Dipole2D
inline bool operator !=(const Dipole2D& d, const Dipole2D& f)
{
return ((d.g != f.g) || (d.p != f.p));
}
// ==============================================
// Circle2D
// ==============================================
/// @brief Encapsulates a 2D circle in conformal geometric algebra.
///
/// The \c Circle2D class is used to store a two-dimensional circle with a four-dimensional trivector representation in conformal geometric algebra.
///
/// @sa RoundPoint3D
/// @sa Dipole3D
class Circle2D
{
public:
float w, x, y, z;
TERATHON_API static const ConstCircle2D zero;
/// @brief Default constructor that leaves the components uninitialized.
inline Circle2D() = default;
/// @brief Constructor that sets components explicitly.
/// @param cw,cx,cy,cz The components of the circle.
Circle2D(float cw, float cx, float cy, float cz)
{
w = cw;
x = cx;
y = cy;
z = cz;
}
/// @brief Sets all four components of a 3D circle.
/// @param cw,cx,cy,cz The new components of the circle.
Circle2D& Set(float cw, float cx, float cy, float cz)
{
w = cw;
x = cx;
y = cy;
z = cz;
return (*this);
}
void Set(float cw, float cx, float cy, float cz) volatile
{
w = cw;
x = cx;
y = cy;
z = cz;
}
Circle2D& operator *=(float n)
{
w *= n;
x *= n;
y *= n;
z *= n;
return (*this);
}
Circle2D& operator /=(float n)
{
n = 1.0F / n;
w *= n;
x *= n;
y *= n;
z *= n;
return (*this);
}
Circle2D& Unitize(void)
{
float n = -1.0F / w;
x *= n;
y *= n;
z *= n;
w = -1.0F;
return (*this);
}
};
/// @brief Returns the negation of the 2D circle \c c.
/// @related Circle2D
inline Circle2D operator -(const Circle2D& c)
{
return (Circle2D(-c.w, -c.x, -c.y, -c.z));
}
/// @brief Returns the product of the 2D circle \c c and the scalar \c n.
/// @related Circle2D
inline Circle2D operator *(const Circle2D& c, float n)
{
return (Circle2D(c.w * n, c.x * n, c.y * n, c.z * n));
}
/// @brief Returns the product of the 2D circle \c c and the scalar \c n.
/// @related Circle2D
inline Circle2D operator *(float n, const Circle2D& c)
{
return (Circle2D(n * c.w, n * c.x, n * c.y, n * c.z));
}
/// @brief Returns the product of the 2D circle \c c and the inverse of the scalar \c n.
/// @related Circle2D
inline Circle2D operator /(const Circle2D& c, float n)
{
n = 1.0F / n;
return (Circle2D(c.w * n, c.x * n, c.y * n, c.z * n));
}
/// @brief Returns a boolean value indicating whether the two 2D circles \c c and \c o are equal.
/// @related Circle2D
inline bool operator ==(const Circle2D& c, const Circle2D& o)
{
return ((c.w == o.w) && (c.x == o.x) && (c.y == o.y) && (c.z == o.z));
}
/// @brief Returns a boolean value indicating whether the two 2D circles \c c and \c o are not equal.
/// @related Circle2D
inline bool operator !=(const Circle2D& c, const Circle2D& o)
{
return ((c.w != o.w) || (c.x != o.x) || (c.y != o.y) || (c.z != o.z));
}
// ==============================================
// Dual
// ==============================================
/// @brief Returns the dual of the 2D round point \c a, which is a 2D circle.
/// @relatedalso RoundPoint2D
inline Circle2D Dual(const RoundPoint2D& a)
{
return (Circle2D(-a.z, a.x, a.y, -a.w));
}
/// @brief Returns the dual of the 2D dipole \c d, which is a 2D dipole.
/// @relatedalso Dipole2D
inline Dipole2D Dual(const Dipole2D& d)
{
return (Dipole2D(d.g.y, -d.g.x, -d.p.z, -d.p.y, d.p.x, -d.g.z));
}
/// @brief Returns the dual of the 2D circle \c c, which is a 2D round point.
/// @relatedalso Circle2D
inline RoundPoint2D Dual(const Circle2D& c)
{
return (RoundPoint2D(c.x, c.y, -c.w, -c.z));
}
// ==============================================
// Reverse
// ==============================================
/// @brief Returns the reverse of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline const RoundPoint2D& Reverse(const RoundPoint2D& a)
{
return (a);
}
/// @brief Returns the reverse of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline Dipole2D Reverse(const Dipole2D& d)
{
return (Dipole2D(-d.g.x, -d.g.y, -d.g.z, -d.p.x, -d.p.y, -d.p.z));
}
/// @brief Returns the reverse of the 2D circle \c c.
/// @relatedalso Circle2D
inline Circle2D Reverse(const Circle2D& c)
{
return (Circle2D(-c.w, -c.x, -c.y, -c.z));
}
// ==============================================
// Antireverse
// ==============================================
/// @brief Returns the antireverse of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline RoundPoint2D Antireverse(const RoundPoint2D& a)
{
return (RoundPoint2D(-a.x, -a.y, -a.z, a.w));
}
/// @brief Returns the antireverse of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline Dipole2D Antireverse(const Dipole2D& d)
{
return (Dipole2D(-d.g.x, -d.g.y, -d.g.z, -d.p.x, -d.p.y, -d.p.z));
}
/// @brief Returns the antireverse of the 2D circle \c c.
/// @relatedalso Circle2D
inline const Circle2D& Antireverse(const Circle2D& c)
{
return (c);
}
inline RoundPoint2D operator ~(const RoundPoint2D& a) {return (Antireverse(a));}
inline Dipole2D operator ~(const Dipole2D& d) {return (Antireverse(d));}
inline const Circle2D& operator ~(const Circle2D& c) {return (Antireverse(c));}
// ==============================================
// Attitude
// ==============================================
/// @brief Returns the attitude of the 2D round point \c a, which is a scalar.
/// @relatedalso RoundPoint2D
inline float Attitude(const RoundPoint2D& a)
{
return (-a.z);
}
/// @brief Returns the attitude of the 2D dipole \c d, which is a 2D round point.
/// @relatedalso Dipole2D
inline RoundPoint2D Attitude(const Dipole2D& d)
{
return (RoundPoint2D(d.g.y, -d.g.x, 0.0F, -d.p.z));
}
/// @brief Returns the attitude of the 2D circle \c c, which is a 2D dipole.
/// @relatedalso Circle2D
inline Dipole2D Attitude(const Circle2D& c)
{
return (Dipole2D(0.0F, 0.0F, c.w, c.y, -c.x, 0.0F));
}
// ==============================================
// Carrier
// ==============================================
/// @brief Returns the carrier of the 2D round point \c a, which is a 2D flat point.
/// @relatedalso RoundPoint2D
inline FlatPoint2D Carrier(const RoundPoint2D& a)
{
return (FlatPoint2D(a.x, a.y, a.z));
}
/// @brief Returns the carrier of the 2D dipole \c d, which is a 2D line.
/// @relatedalso Dipole2D
inline Line2D Carrier(const Dipole2D& d)
{
return (Line2D(d.g.x, d.g.y, d.g.z));
}
// ==============================================
// Cocarrier
// ==============================================
/// @brief Returns the cocarrier of the 2D dipole \c d, which is a 2D line.
/// @relatedalso Dipole3D
inline Line2D Cocarrier(const Dipole2D& d)
{
return (Line2D(-d.g.y, d.g.x, -d.p.z));
}
/// @brief Returns the cocarrier of the 2D circle \c c, which is a 2D flat point.
/// @relatedalso Circle2D
inline FlatPoint2D Cocarrier(const Circle2D& c)
{
return (FlatPoint2D(-c.x, -c.y, c.w));
}
// ==============================================
// Center
// ==============================================
/// @brief Returns the center of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline RoundPoint2D Center(const RoundPoint2D& a)
{
return (RoundPoint2D(a.x * a.z, a.y * a.z, a.z * a.z, a.z * a.w));
}
/// @brief Returns the center of the 2D dipole \c d.
/// @relatedalso Dipole2D
TERATHON_API RoundPoint2D Center(const Dipole2D& d);
/// @brief Returns the center of the 2D circle \c c.
/// @relatedalso Circle2D
inline RoundPoint2D Center(const Circle2D& c)
{
return (RoundPoint2D(-c.x * c.w, -c.y * c.w, c.w * c.w, c.x * c.x + c.y * c.y - c.z * c.w));
}
// ==============================================
// FlatCenter
// ==============================================
/// @brief Returns the flat center of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline FlatPoint2D FlatCenter(const RoundPoint2D& a)
{
return (FlatPoint2D(a.x, a.y, a.z));
}
/// @brief Returns the flat center of the 2D dipole \c d.
/// @relatedalso Dipole2D
TERATHON_API FlatPoint2D FlatCenter(const Dipole2D& d);
/// @brief Returns the flat center of the 3D sphere \c s.
/// @relatedalso Sphere3D
inline FlatPoint2D FlatCenter(const Circle2D& c)
{
return (FlatPoint2D(-c.x, -c.y, c.w));
}
// ==============================================
// Container
// ==============================================
/// @brief Returns the container of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline Circle2D Container(const RoundPoint2D& a)
{
return (Circle2D(-a.z * a.z, a.x * a.z, a.y * a.z, a.z * a.w - a.x * a.x - a.y * a.y));
}
/// @brief Returns the container of the 2D dipole \c d.
/// @relatedalso Dipole2D
TERATHON_API Circle2D Container(const Dipole2D& d);
/// @brief Returns the container of the 2D circle \c c.
/// @relatedalso Circle2D
inline Circle2D Container(const Circle2D& c)
{
return (Circle2D(-c.w * c.w, -c.x * c.w, -c.y * c.w, -c.z * c.w));
}
// ==============================================
// Partner
// ==============================================
/// @brief Returns the partner of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline RoundPoint2D Partner(const RoundPoint2D& a)
{
float z2 = a.z * a.z;
return (RoundPoint2D(a.x * z2, a.y * z2, a.z * z2, (a.x * a.x + a.y * a.y - a.z * a.w) * a.z));
}
/// @brief Returns the partner of the 2D dipole \c d.
/// @relatedalso Dipole2D
TERATHON_API Dipole2D Partner(const Dipole2D& d);
/// @brief Returns the partner of the 2D circle \c c.
/// @relatedalso Circle2D
inline Circle2D Partner(const Circle2D& c)
{
float w2 = c.w * c.w;
return (Circle2D(c.w * w2, c.x * w2, c.y * w2, (c.x * c.x + c.y * c.y - c.z * c.w) * c.w));
}
// ==============================================
// SquaredRadiusNorm
// ==============================================
/// @brief Returns the squared radius of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredRadiusNorm(const RoundPoint2D& a)
{
return (a.z * a.w * 2.0F - a.x * a.x - a.y * a.y);
}
/// @brief Returns the squared radius of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredRadiusNorm(const Dipole2D& d)
{
return (d.p.z * d.p.z - d.g.z * d.g.z - (d.g.x * d.p.y - d.g.y * d.p.x) * 2.0F);
}
/// @brief Returns the squared radius of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredRadiusNorm(const Circle2D& c)
{
return (c.x * c.x + c.y * c.y - c.z * c.w * 2.0F);
}
// ==============================================
// SquaredCenterNorm
// ==============================================
/// @brief Returns the squared distance from the origin to the center of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredCenterNorm(const RoundPoint2D& a)
{
return (a.x * a.x + a.y * a.y);
}
/// @brief Returns the squared distance from the origin to the center of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredCenterNorm(const Dipole2D& d)
{
return (d.g.z * d.g.z + d.p.z * d.p.z);
}
/// @brief Returns the squared distance from the origin to the center of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredCenterNorm(const Circle2D& c)
{
return (c.x * c.x + c.y * c.y);
}
// ==============================================
// SquaredBulkNorm
// ==============================================
/// @brief Returns the squared round bulk of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredBulkNorm(const RoundPoint2D& a)
{
return (a.x * a.x + a.y * a.y);
}
/// @brief Returns the squared round bulk of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredBulkNorm(const Dipole2D& d)
{
return (d.g.z * d.g.z);
}
/// @brief Returns the squared round bulk of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredBulkNorm(const Circle2D& c)
{
return (0.0F);
}
// ==============================================
// SquaredWeightNorm
// ==============================================
/// @brief Returns the squared round weight of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredWeightNorm(const RoundPoint2D& a)
{
return (a.z * a.z);
}
/// @brief Returns the squared round weight of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredWeightNorm(const Dipole2D& d)
{
return (d.g.x * d.g.x + d.g.y * d.g.y);
}
/// @brief Returns the squared round weight of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredWeightNorm(const Circle2D& c)
{
return (c.w * c.w);
}
// ==============================================
// SquaredFlatBulkNorm
// ==============================================
/// @brief Returns the squared flat bulk of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredFlatBulkNorm(const RoundPoint2D& a)
{
return (a.w * a.w);
}
/// @brief Returns the squared flat bulk of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredFlatBulkNorm(const Dipole2D& d)
{
return (d.p.x * d.p.x + d.p.y * d.p.y);
}
/// @brief Returns the squared flat bulk of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredFlatBulkNorm(const Circle2D& c)
{
return (c.z * c.z);
}
// ==============================================
// SquaredFlatWeightNorm
// ==============================================
/// @brief Returns the squared flat weight of the 2D round point \c a.
/// @relatedalso RoundPoint2D
inline float SquaredFlatWeightNorm(const RoundPoint2D& a)
{
return (0.0F);
}
/// @brief Returns the squared flat weight of the 2D dipole \c d.
/// @relatedalso Dipole2D
inline float SquaredFlatWeightNorm(const Dipole2D& d)
{
return (d.p.z * d.p.z);
}
/// @brief Returns the squared flat weight of the 2D circle \c c.
/// @relatedalso Circle2D
inline float SquaredFlatWeightNorm(const Circle2D& c)
{
return (c.x * c.x + c.y * c.y);
}
// ==============================================
// Unitize
// ==============================================
/// @brief Calculates the unitized equivalent of a 2D round point.
///
/// Multiplies the 2D round point \c a by the inverse magnitude of its weight, which is its <i>z</i> component.
/// The return value is a round point having a <i>z</i> coordinate of one.
///
/// @relatedalso RoundPoint2D
inline RoundPoint2D Unitize(const RoundPoint2D& a)
{
float n = 1.0F / a.z;
return (RoundPoint2D(a.x * n, a.y * n, 1.0F, a.w * n));
}
/// @brief Calculates the unitized equivalent of a 2D dipole.
///
/// Multiplies the 2D dipole \c d by the inverse magnitude of its weight, which is the 2D bivector given by its
/// <i>gx</i> and <i>gy</i> coordinates. The carrier line of the returned dipole has a unit-length normal.
///
/// @relatedalso Dipole2D
inline Dipole2D Unitize(const Dipole2D& d)
{
return (d * InverseSqrt(d.g.x * d.g.x + d.g.y * d.g.y));
}
/// @brief Calculates the unitized equivalent of a 2D circle.
///
/// Multiplies the 2D circle \c c by the negated inverse magnitude of its weight, which is its <i>w</i> component.
/// The return value is a circle having a <i>w</i> coordinate of negative one.
///
/// @relatedalso Circle2D
inline Circle2D Unitize(const Circle2D& c)
{
float n = -1.0F / c.w;
return (Circle2D(-1.0F, c.x * n, c.y * n, c.z * n));
}
// ==============================================
// Join
// ==============================================
/// @brief Calculates the join of the 2D round points \c a and \c b to produce a 2D dipole.
/// @relatedalso RoundPoint2D
TERATHON_API Dipole2D Wedge(const RoundPoint2D& a, const RoundPoint2D& b);
/// @brief Calculates the join of the 2D flat point \c p and 2D round point \c a to produce a 2D line.
/// @relatedalso Line2D
TERATHON_API Line2D Wedge(const FlatPoint2D& p, const RoundPoint2D& a);
/// @brief Calculates the join of the 2D Euclidean point \c p and 2D round point \c a to produce a 2D line.
/// @relatedalso Line2D
TERATHON_API Line2D Wedge(const Point2D& p, const RoundPoint2D& a);
/// @brief Calculates the join of the 2D dipole \c d and 2D round point \c a to produce a 2D circle.
/// @relatedalso Circle2D
TERATHON_API Circle2D Wedge(const Dipole2D& d, const RoundPoint2D& a);
inline Line2D Wedge(const RoundPoint2D& a, const FlatPoint2D& p) {return (Wedge(p, a));}
inline Line2D Wedge(const RoundPoint2D& a, const Point2D& p) {return (Wedge(p, a));}
inline Circle2D Wedge(const RoundPoint2D& a, const Dipole2D& d) {return (Wedge(d, a));}
inline Dipole2D operator ^(const RoundPoint2D& a, const RoundPoint2D& b) {return (Wedge(a, b));}
inline Line2D operator ^(const FlatPoint2D& p, const RoundPoint2D& a) {return (Wedge(p, a));}
inline Line2D operator ^(const Point2D& p, const RoundPoint2D& a) {return (Wedge(p, a));}
inline Circle2D operator ^(const Dipole2D& d, const RoundPoint2D& a) {return (Wedge(d, a));}
inline Line2D operator ^(const RoundPoint2D& a, const FlatPoint2D& p) {return (Wedge(p, a));}
inline Line2D operator ^(const RoundPoint2D& a, const Point2D& p) {return (Wedge(p, a));}
inline Circle2D operator ^(const RoundPoint2D& a, const Dipole2D& d) {return (Wedge(d, a));}
// ==============================================
// Meet
// ==============================================
/// @brief Calculates the meet of the 2D circles \c c and \c o to produce a 2D dipole.
/// @relatedalso Dipole2D
TERATHON_API Dipole2D Antiwedge(const Circle2D& c, const Circle2D& o);
/// @brief Calculates the meet of the 2D circle \c c and 2D line \c g to produce a 2D dipole.
/// @relatedalso Dipole2D
TERATHON_API Dipole2D Antiwedge(const Circle2D& c, const Line2D& g);
/// @brief Calculates the meet of the 2D line \c g and 2D circle \c c to produce a 2D dipole.
/// @relatedalso Dipole2D
TERATHON_API Dipole2D Antiwedge(const Line2D& g, const Circle2D& c);
/// @brief Calculates the meet of the 2D circle \c c and 2D dipole \c d to produce a 2D round point.
/// @relatedalso RoundPoint2D
TERATHON_API RoundPoint2D Antiwedge(const Circle2D& c, const Dipole2D& d);