GteContScribeCircle2.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
12 
13 namespace gte
14 {
15 
16 // All functions return 'true' if the circle has been constructed, 'false'
17 // otherwise (input points are linearly dependent).
18 
19 // Circle circumscribing triangle.
20 template <typename Real>
21 bool Circumscribe(Vector2<Real> const& v0, Vector2<Real> const& v1,
22  Vector2<Real> const& v2, Circle2<Real>& circle);
23 
24 // Circle inscribing triangle.
25 template <typename Real>
26 bool Inscribe(Vector2<Real> const& v0, Vector2<Real> const& v1,
27  Vector2<Real> const& v2, Circle2<Real>& circle);
28 
29 
30 template <typename Real>
32  Vector2<Real> const& v2, Circle2<Real>& circle)
33 {
34  Vector2<Real> e10 = v1 - v0;
35  Vector2<Real> e20 = v2 - v0;
36  Matrix2x2<Real> A{ e10[0], e10[1], e20[0], e20[1] };
37  Vector2<Real> B{ ((Real)0.5)*Dot(e10, e10), ((Real)0.5)*Dot(e20, e20) };
38  Vector2<Real> solution;
39  if (LinearSystem<Real>::Solve(A, B, solution))
40  {
41  circle.center = v0 + solution;
42  circle.radius = Length(solution);
43  return true;
44  }
45  return false;
46 }
47 
48 template <typename Real>
50  Vector2<Real> const& v2, Circle2<Real>& circle)
51 {
52  Vector2<Real> d10 = v1 - v0;
53  Vector2<Real> d20 = v2 - v0;
54  Vector2<Real> d21 = v2 - v1;
55  Real len10 = Length(d10);
56  Real len20 = Length(d20);
57  Real len21 = Length(d21);
58  Real perimeter = len10 + len20 + len21;
59  if (perimeter > (Real)0)
60  {
61  Real inv = ((Real)1) / perimeter;
62  len10 *= inv;
63  len20 *= inv;
64  len21 *= inv;
65  circle.center = len21*v0 + len20*v1 + len10*v2;
66  circle.radius = inv*std::abs(DotPerp(d10, d20));
67  return circle.radius > (Real)0;
68  }
69  return false;
70 }
71 
72 
73 }
bool Inscribe(Vector2< Real > const &v0, Vector2< Real > const &v1, Vector2< Real > const &v2, Circle2< Real > &circle)
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
GLfloat GLfloat v1
Definition: glcorearb.h:812
Real DotPerp(Vector2< Real > const &v0, Vector2< Real > const &v1)
Definition: GteVector2.h:117
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLfloat v0
Definition: glcorearb.h:811
DualQuaternion< Real > Length(DualQuaternion< Real > const &d, bool robust=false)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:813
bool Circumscribe(Vector2< Real > const &v0, Vector2< Real > const &v1, Vector2< Real > const &v2, Circle2< Real > &circle)
Vector< N, Real > center


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59