TinyVector.cxx
1 #ifndef SELDON_FILE_TINY_VECTOR_CXX
2 
3 #include "TinyVector.hxx"
4 
5 namespace Seldon
6 {
7 
9 
18  template<class T>
19  int IntersectionEdges(const TinyVector<T,2>& pointA, const TinyVector<T,2>& pointB,
20  const TinyVector<T,2>& pt1, const TinyVector<T,2>& pt2,
21  TinyVector<T,2>& res, const T& threshold)
22  {
23  T dx = pointB(0)-pointA(0);
24  T dy = pointB(1)-pointA(1);
25  T dxj = pt2(0)-pt1(0);
26  T dyj = pt2(1)-pt1(1);
27  T delta = dx*dyj-dy*dxj;
28  T x, y, zero;
29  SetComplexZero(zero);
30  if (delta != zero)
31  {
32  x = (dxj*dx*(pointA(1)-pt1(1))+pt1(0)*dyj*dx-pointA(0)*dy*dxj)/delta;
33  y = -(dyj*dy*(pointA(0)-pt1(0))+pt1(1)*dxj*dy-pointA(1)*dx*dyj)/delta;
34  // DISP(x); DISP(y); DISP((x-pt1(0))*(x-pt2(0)));
35  // DISP((y-pt1(1))*(y-pt2(1)));DISP((x-pointA(0))*(x-pointB(0)));
36  // DISP((y-pointA(1))*(y-pointB(1)));
37  if (((x-pt1(0))*(x-pt2(0)))<=threshold)
38  {
39  if (((y-pt1(1))*(y-pt2(1)))<=threshold)
40  {
41  if (((x-pointA(0))*(x-pointB(0)))<=threshold)
42  {
43  if (((y-pointA(1))*(y-pointB(1)))<=threshold)
44  {
45  res.Init(x,y);
46  return 1;
47  }
48  }
49  }
50  }
51  }
52  else
53  {
54  if (abs(dx*(pt1(1)-pointA(1))-dy*(pt1(0)-pointA(0)))<=threshold)
55  {
56  return 2;
57  }
58  }
59  return 0;
60  }
61 
62 
64 
73  template<class T>
74  int IntersectionDroites(const TinyVector<T,2>& pointA, const TinyVector<T,2>& pointB,
75  const TinyVector<T,2>& pt1, const TinyVector<T,2>& pt2,
76  TinyVector<T,2>& res, const T& threshold)
77  {
78  T dx = pointB(0)-pointA(0);
79  T dy = pointB(1)-pointA(1);
80  T dxj = pt2(0)-pt1(0);
81  T dyj = pt2(1)-pt1(1);
82  T delta = dx*dyj-dy*dxj;
83  T x,y, zero;
84  SetComplexZero(zero);
85  if (abs(delta) > threshold)
86  {
87  x=(dxj*dx*(pointA(1)-pt1(1))+pt1(0)*dyj*dx-pointA(0)*dy*dxj)/delta;
88  if (abs(dx) > abs(dxj))
89  y = dy/dx*(x-pointA(0)) + pointA(1);
90  else
91  y = dyj/dxj*(x-pt1(0)) + pt1(1);
92 
93  res.Init(x,y);
94  return 1;
95  }
96  else
97  {
98  if (abs(dx*(pt1(1)-pointA(1))-dy*(pt1(0)-pointA(0))) <= threshold)
99  {
100  return 2;
101  }
102  }
103 
104  return 0;
105  }
106 
107 
109  template<class T>
110  void GetVectorPlane(const TinyVector<T,3>& normale,
112  {
113  Vector<T> coord(3); IVect perm(3);
114  perm.Fill();
115  for (int i = 0; i < 3; i++)
116  coord(i) = abs(normale(i));
117 
118  Sort(3, coord, perm);
119  u1.Zero(); u1(perm(2)) = -normale(perm(1));
120  u1(perm(1)) = normale(perm(2));
121 
122  // le dernier vecteur est obtenu avec un produit vectoriel
123  TimesProd(normale, u1, u2);
124 
125  typename ClassComplexType<T>::Treal one;
126  SetComplexOne(one);
127  Mlt(one/Norm2(u1), u1); Mlt(one/Norm2(u2), u2);
128  }
129 
130 } // end namespace
131 
132 #define SELDON_FILE_TINY_VECTOR_CXX
133 #endif
Seldon::TimesProd
void TimesProd(const TinyVector< T1, 3 > &u, const TinyVector< T2, 3 > &v, TinyVector< T3, 3 > &res)
cross product res = u^v where u,v and res are vectors
Definition: TinyVectorInline.cxx:1455
Seldon::Norm2
ClassComplexType< T >::Treal Norm2(const VectorExpression< T, E > &X)
returns 2-norm of an expression with vectors
Definition: Functions_BaseInline.cxx:153
Seldon::Vector< T >
Seldon::TinyVector
vector with real/complex components
Definition: TinyVector.hxx:17
Seldon
Seldon namespace.
Definition: Array.cxx:24