ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
exact_predicates_gmp.h
浏览该文件的文档.
1 #pragma once
3 
4 #ifdef VDE_USE_GMP
5 #include <gmpxx.h>
6 
7 namespace vde::foundation::exact {
8 
20 struct GmpExact {
22  using Rational = mpq_class;
23 
42  static Orientation orient_2d(const Point2D& a, const Point2D& b, const Point2D& c) {
43  Rational ax(a.x()), ay(a.y());
44  Rational bx(b.x()), by(b.y());
45  Rational cx(c.x()), cy(c.y());
46  Rational det = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
47  int s = mpq_sgn(det.get_mpq_t());
48  return s > 0 ? Orientation::CounterClockwise :
50  }
51 
63  static Orientation orient_3d(const Point3D& a, const Point3D& b,
64  const Point3D& c, const Point3D& d) {
65  Rational ax(a.x()), ay(a.y()), az(a.z());
66  Rational bx(b.x()), by(b.y()), bz(b.z());
67  Rational cx(c.x()), cy(c.y()), cz(c.z());
68  Rational dx(d.x()), dy(d.y()), dz(d.z());
69 
70  Rational adx = ax - dx, ady = ay - dy, adz = az - dz;
71  Rational bdx = bx - dx, bdy = by - dy, bdz = bz - dz;
72  Rational cdx = cx - dx, cdy = cy - dy, cdz = cz - dz;
73 
74  Rational det = adx * (bdy * cdz - bdz * cdy)
75  + bdx * (cdy * adz - cdz * ady)
76  + cdx * (ady * bdz - adz * bdy);
77 
78  int s = mpq_sgn(det.get_mpq_t());
79  return s > 0 ? Orientation::CounterClockwise :
81  }
82 
94  static CircleTest in_circle(const Point2D& a, const Point2D& b,
95  const Point2D& c, const Point2D& d) {
96  Rational ax(a.x()), ay(a.y());
97  Rational bx(b.x()), by(b.y());
98  Rational cx(c.x()), cy(c.y());
99  Rational dx(d.x()), dy(d.y());
100 
101  Rational adx = ax - dx, ady = ay - dy;
102  Rational bdx = bx - dx, bdy = by - dy;
103  Rational cdx = cx - dx, cdy = cy - dy;
104 
105  Rational ab = adx * bdy - ady * bdx;
106  Rational bc = bdx * cdy - bdy * cdx;
107  Rational ca = cdx * ady - cdy * adx;
108  Rational al = adx * adx + ady * ady;
109  Rational bl = bdx * bdx + bdy * bdy;
110  Rational cl = cdx * cdx + cdy * cdy;
111 
112  Rational det = al * bc + bl * ca + cl * ab;
113  int s = mpq_sgn(det.get_mpq_t());
114  return s > 0 ? CircleTest::Inside :
116  }
117 };
118 
119 } // namespace vde::foundation::exact
120 
121 #endif // VDE_USE_GMP
Orientation orient_3d(const Point3D &a, const Point3D &b, const Point3D &c, const Point3D &d)
自适应精度三维定向测试
Orientation orient_2d(const Point2D &a, const Point2D &b, const Point2D &c)
自适应精度二维定向测试(Shewchuk 算法)
CircleTest in_circle(const Point2D &a, const Point2D &b, const Point2D &c, const Point2D &d)
自适应精度圆内测试(In-Circle Test)
Orientation
二维定向测试结果
CircleTest
圆测试结果
Point< double, 2 > Point2D
双精度二维点
Definition: math_types.h:41
Point< double, 3 > Point3D
双精度三维点
Definition: math_types.h:43