MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Vector.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _MGVector_HH_
6 #define _MGVector_HH_
7 
11 #include <stddef.h>
12 #include <vector>
13 #include "mg/MGCL.h"
14 
15 // MGVector.h
16 // Header for MGVector.
17 
18 //Forward Declaration
19 class MGUnit_vector;
20 class MGPosition;
21 class MGIfstream;
22 class MGOfstream;
23 class MGIgesOfstream;
24 
26 class MG_DLL_DECLR MGVector {
27 
28 public:
29 
32 MG_DLL_DECLR friend MGVector operator+(const MGVector& vec1,const MGVector& vec2);
33 
36 MG_DLL_DECLR friend MGVector operator-(const MGVector& vec1,const MGVector& vec2);
37 
40 MG_DLL_DECLR friend double operator%(const MGVector& vec1,const MGVector& vec2);
41 
44 MG_DLL_DECLR friend MGVector operator*(const MGVector& vec1,const MGVector& vec2);
45 
48 MG_DLL_DECLR friend MGVector operator*(const MGVector& vec1,double scale);
49 
52 MG_DLL_DECLR friend MGVector operator* (double, const MGVector&);
53 
56 MG_DLL_DECLR friend MGVector operator/(const MGVector& vec1,double scale);
57 
60 inline friend
61 bool operator<(const MGVector& v1,const MGVector& v2){return v1.len()<v2.len();};
62 inline friend
63 bool operator<=(const MGVector& v1,const MGVector& v2){return v1.len()<=v2.len();};
64 inline friend
65 bool operator>(const MGVector& v1,const MGVector& v2){return v1.len()>v2.len();};
66 inline friend
67 bool operator>=(const MGVector& v1,const MGVector& v2){return v1.len()>=v2.len();};
68 
71 MG_DLL_DECLR friend bool operator==(const MGVector& v1,const MGVector& v2);
72 
75 inline friend bool operator!=(const MGVector& v1,const MGVector& v2){return !(v1==v2);}
76 
78 MG_DLL_DECLR friend std::ostream& operator<< (std::ostream&, const MGVector&);
79 
82 MG_DLL_DECLR friend double MGDeterminant(
83  const MGVector& v1, const MGVector& v2, const MGVector& v3
84 );
85 
87 
89 explicit MGVector(int sdim=0);
90 
92 MGVector(double x, double y);
93 
95 MGVector(double x, double y , double z);
96 
98 MGVector(double x, double y, double z, double w);
99 
102 MGVector(int sdim, double v);
103 
107 MGVector(int sdim, const double* v);
108 
111 MGVector(const MGPosition&);
112 
114 MGVector(
115  const MGVector& dvec,
116  const MGVector& svec
117 );
118 
122 MGVector(
123  int sdim,
124  const MGVector& vec2,
125  int start1=0,
126  int start2=0
128 );
129 
131 MGVector(const std::vector<double>& darrays);
132 
135 
137 MGVector ( const MGVector& );
138 
140 ~MGVector(){if(m_sdim>3) delete[] m_element;}
141 
143 
145 MGVector& operator =(const MGVector &);
146 
148 double operator() (int i) const{return ref(i);}
149 
151 double operator[] (int i) const{return ref(i);}
152 
156 double& operator()(int i);
157 
159 MGVector& operator=(const double*);
160 
163 MGVector & operator+= (const MGVector&);
164 
167 MGVector operator- () const;
168 
171 MGVector & operator -= ( const MGVector & );
172 
175 MGVector& operator*= (double scale);
176 
178 MGVector& operator*= (const MGVector& vec2);
179 
182 MGVector& operator/= (double scale);
183 
185 
189 double angle(const MGVector&) const;
190 
193 double anglepai(const MGVector& v2)const{return angle(v2);};
194 
200 double angle2pai(const MGVector& v2, const MGVector& N)const;
201 
205 double cangle(const MGVector&) const;
206 
208 MGVector& clear(double init=0.0);
209 
211 const double* data()const{return m_element;};
212 double* data(){return m_element;};
213 
217 MGVector interpolate(double t, const MGVector& vec2) const;
218 
227 MGVector interpolate_by_rotate(
228  double t, const MGVector& vec2,
229  double* ratio=0
230 ) const;
231 
236  const MGVector& v2
237 )const{ return (*this).parallel(v2);}
238 
242 bool is_collinear(
243  const MGVector& v2,
244  const MGVector& v3
245 )const;
246 
248 bool is_null()const{return m_sdim==0;}
249 
252 bool is_unit_vector() const;
253 
255 bool is_zero_vector() const;
256 
259 double len() const;
260 
262 void negate(){operator*=(-1.);};
263 
266 MGUnit_vector normalize() const;
267 
271 bool orthogonal(const MGVector& ) const;
272 
275 int out_to_IGES(
276  MGIgesOfstream& igesfile,
277  int SubordinateEntitySwitch=0
278 )const;
279 
283 MGVector orthogonize(const MGVector& vec2)const;
284 
287 bool parallel(const MGVector& ) const;
288 
291 MGVector project(const MGVector& v2) const;
292 
294 double ref(int i) const{
295  if(i<sdim()) return m_element[i];
296  else return 0.;
297 }
298 
301 void resize(int new_sdim);
302 
306 double sangle(const MGVector& ) const;
307 
309 int sdim() const { return m_sdim; };
310 
312 void set_null();
313 
315 void set_unit();
316 
321 void store_at(
322  int i,
323  const MGVector& vec2,
324  int j=0
325 );
326 
330 void store_at(
331  int i,
332  const MGVector& vec2,
333  int j,
334  int len
335 );
336 
339 void swap(int i, int j);
340 
343 int dump_size() const;
345 int dump(MGOfstream& ) const;
346 
348 int restore(MGIfstream& );
349 
351 
352 protected:
354  int m_sdim;
355  double* m_element;
356  double m_data[3];
357  mutable double m_length;
358 
364  double& set(int i) {return m_element[i];}
365 
366 friend class MGLBRep;
367 friend class MGSBRep;
368 
369 };
370 
371 namespace MGCL{
372 
374 
376 MG_DLL_DECLR MGVector project(const MGVector& V1, const MGVector& V2);
377 
378 };
379  // end of BASE group
381 #endif
double m_length
For vector data of space dimension less or equal to 3.
Definition: Vector.h:357
double * m_element
Definition: Vector.h:355
void negate()
Negate the vector.
Definition: Vector.h:262
double anglepai(const MGVector &v2) const
Definition: Vector.h:193
double ref(int i) const
Reference to i-th element.
Definition: Vector.h:294
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
friend bool operator<=(const MGVector &v1, const MGVector &v2)
Definition: Vector.h:63
std::ostream & operator<<(std::ostream &ostrm, const MGisect &is)
Debug Function.
Definition: isect.h:95
friend bool operator!=(const MGVector &v1, const MGVector &v2)
Definition: Vector.h:75
MGLBRep is a class for B-SPline representation.
Definition: LBRep.h:41
bool is_null() const
Test if this is null.
Definition: Vector.h:248
MG_DLL_DECLR MGVector & operator*=(MGVector &v, const MGMatrix &m)
Vector of a general n space dimension.
Definition: Vector.h:26
MG_DLL_DECLR MGVector project(const MGVector &V1, const MGVector &V2)
V1をベクトル(v2)に射影したベクトルを求める。
double * data()
Definition: Vector.h:212
~MGVector()
Definition: Vector.h:140
MG_DLL_DECLR bool is_collinear(const MGPosition &P1, const MGPosition &P2, const MGPosition &P3)
Test if P1, P2, and P3 are on a single straight line.
MG_DLL_DECLR MGVector operator*(const MGVector &v, const MGMatrix &m)
double len() const
Represent a positional data.
Definition: Position.h:28
int sdim() const
Get the space dimension.
Definition: Vector.h:309
int m_sdim
Friend Function.
Definition: Vector.h:354
Definition: Curve.h:1282
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
bool is_collinear(const MGVector &v2) const
Definition: Vector.h:235
friend bool operator<(const MGVector &v1, const MGVector &v2)
Definition: Vector.h:61
friend bool operator>(const MGVector &v1, const MGVector &v2)
Definition: Vector.h:65
friend bool operator>=(const MGVector &v1, const MGVector &v2)
Definition: Vector.h:67
MGOgesIfstream write out to *.iges file, transforming MGCL objects to IGES objects.
Definition: IgesOfstream.h:26
double & set(int i)
When length not computed, negative value will be set.
Definition: Vector.h:364
Defines Surface B-Representation, that is , B-Spline surface.
Definition: SBRep.h:48
Define a unit vector, is a MGVector.
Definition: Unit_vector.h:17
const double * data() const
Return the 1st address of the array of the vector double data.
Definition: Vector.h:211