AnyCAD C++ API  2018
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 
APIMath.h
浏览该文件的文档.
1 #pragma once
2 
3 #include <vector>
4 
5 namespace AnyCAD{ namespace API{
6 
7  typedef double Real;
8  typedef void* Handle;
9 
17  {
18  public:
21  public:
23  :x(0), y(0)
24 
25  {}
26  Vector2(Real _x, Real _y)
27  :x(_x), y(_y)
28  {}
29  };
30  typedef std::vector<Vector2> Vector2List;
38  {
39  public:
43  public:
45  :x(0), y(0), z(0)
46 
47  {}
48  Vector3(Real _x, Real _y, Real _z)
49  :x(_x), y(_y), z(_z)
50  {}
51 
55  Vector3 operator-(const Vector3& rhv) const
56  {
57  return Vector3(x-rhv.x, y-rhv.y, z-rhv.z);
58  }
62  Vector3 operator+(const Vector3& rhv) const
63  {
64  return Vector3(x+rhv.x, y+rhv.y, z+rhv.z);
65  }
69  Vector3 operator*(const Vector3& rhv) const
70  {
71  return Vector3(x*rhv.x, y*rhv.y, z*rhv.z);
72  }
77  {
78  return Vector3(x*vv, y*vv, z*vv);
79  }
84  {
85  return Vector3(x/vv, y/vv, z/vv);
86  }
90  Real length() const;
94  Real distance(const Vector3& pt) const;
98  Real dotProduct(const Vector3& pt) const;
102  Real normalize();
103 
107  Vector3 crossProduct(const Vector3& pt) const;
111  Real angleBetween(const Vector3& vv) const;
116  Vector3 angleBetweenZUp(Real angleZ) const;
117 
118 
119  public:
120  static const Vector3 ZERO;
121  static const Vector3 UNIT_X;
122  static const Vector3 UNIT_Y;
123  static const Vector3 UNIT_Z;
124  };
132  {
133  public:
134  typedef std::vector<Vector3> Vector3Arr;
135  Vector3List();
136  Vector3List(const Vector3Arr& arr);
140  int size() const { return int(m_arr.size());}
145  void add(const Vector3& vec);
146 
151  Vector3 get(int idx) const;
152 
153 
154  Vector3* ptr() { return &m_arr[0]; }
159  const Vector3& operator[] (int idx) const
160  {
161  return m_arr[idx];
162  }
163 
164  void resize(int nSize){ m_arr.resize(nSize); }
165 
169  void clear() { m_arr.clear(); }
170  public:
171  const Vector3Arr& GetImpl() const {return m_arr; }
172  Vector3Arr& GetImpl() { return m_arr; }
173 
174  protected:
176  };
184  {
185  public:
186  float r;
187  float g;
188  float b;
189  float a;
190  public:
192  : r(0), g(0), b(0), a(0)
193  {
194 
195  }
196  ColorValue(float _r, float _g, float _b, float _a)
197  : r(_r), g(_g), b(_b), a(_a)
198  {
199 
200  }
201  ColorValue(int _r, int _g, int _b, int _a = 255)
202  :r(_r/255.0f), g(_g/255.0f), b(_b/255.0f), a(_a/255.0f)
203  {
204 
205  }
206 
207  long AsRGB() const
208  {
209  return ((long)(((unsigned char)(r*255)|((unsigned short)((unsigned char)(g*255))<<8))|(((unsigned char)(unsigned short)(b*255))<<16)));
210  }
211  };
219  {
220  public:
221  Real m[3][3];
222 
223  public:
225  {
226  }
227 
228  Real Get(int row, int col) const
229  {
230  return m[row][col];
231  }
232 
233  void Set(int row, int col, Real data)
234  {
235  m[row][col] = data;
236  }
237  inline Real* operator[] (size_t iRow) const
238  {
239  return (Real*)m[iRow];
240  }
241  };
249  {
250  public:
251  Real m[4][4];
252  public:
254  {
255 
256  }
257  Real Get(int row, int col) const
258  {
259  return m[row][col];
260  }
261 
262  void Set(int row, int col, Real data)
263  {
264  m[row][col] = data;
265  }
266  inline Real* operator[] (size_t iRow) const
267  {
268  return (Real*)m[iRow];
269  }
270 
271  Vector3 operator * ( const Vector3 &pt ) const{ return transform(pt); }
272 
273  Vector3 transform(const Vector3& pt) const;
274  };
282  {
283  public:
286  public:
287  AABox(){}
288  AABox(const Vector3& _minPt, const Vector3& _maxPt)
289  : minPt(_minPt), maxPt(_maxPt)
290  {
291 
292  }
293 
294  Vector3 GetSize() const { return maxPt - minPt; }
295 
296  Vector3 GetCenter() const {return (maxPt+minPt)/2; }
297 
298  bool intersects(const AABox& b2) const;
299 
300  bool intersects(const Vector3& v) const;
301 
302  void transform(const Matrix4& trf);
303 
304  void Merge(const AABox& b2);
305  };
306 
314  {
315  public:
320  public:
321  Quaternion():w(1.0),x(0),y(0),z(0){}
322  Quaternion(Real _w, Real _x, Real _y, Real _z):w(_w),x(_x),y(_y),z(_z){}
323  Quaternion(const Vector3& src, const Vector3& dest);
329  void FromAngleAxis(const Real& rfAngle, const Vector3& rkAxis);
330 
332  {
339  };
346  bool ToEulerAngles(EnumEularSequence sequence, Vector3& euler) const;
347 
353  Vector3 operator*(const Vector3& vec) const;
354  };
355 
356  typedef std::pair<bool, Real> RayResult;
357 
365  {
366  public:
367  Ray();
368  Ray(const Vector3& origin, const Vector3& direction)
369  :mOrigin(origin), mDirection(direction) {}
370 
374  void setOrigin(const Vector3& origin) {mOrigin = origin;}
378  const Vector3& getOrigin(void) const {return mOrigin;}
379 
383  void setDirection(const Vector3& dir) {mDirection = dir;}
387  const Vector3& getDirection(void) const {return mDirection;}
388 
392  Vector3 getPoint(Real t) const {
393  return Vector3(mOrigin + (mDirection * t));
394  }
395 
402  RayResult Intersect(const Vector3& pos, const Vector3& dir) const;
403 
404  protected:
407  };
408 
409 
417  {
418  public:
419  Coordinate3();
420  Coordinate3(const Vector3& o, const Vector3& x, const Vector3& y, const Vector3& z);
421  ~Coordinate3();
422 
423  public:
428  };
429 }}
#define AnyPlatformAPI_API
Definition: AnyPlatformAPI.h:8
Vector3()
Definition: APIMath.h:44
Vector2(Real _x, Real _y)
Definition: APIMath.h:26
Real x
Definition: APIMath.h:317
void setDirection(const Vector3 &dir)
Definition: APIMath.h:383
Ray.
Definition: APIMath.h:364
Vector3 Y
Definition: APIMath.h:426
Vector3 getPoint(Real t) const
Definition: APIMath.h:392
AABox.
Definition: APIMath.h:281
Definition: APIMath.h:333
void * Handle
Definition: APIMath.h:8
static const Vector3 UNIT_Z
Definition: APIMath.h:123
Vector3 * ptr()
Definition: APIMath.h:154
Quaternion.
Definition: APIMath.h:313
float g
Definition: APIMath.h:187
Matrix4.
Definition: APIMath.h:248
Real z
Definition: APIMath.h:319
Vector3 maxPt
Definition: APIMath.h:285
Real w
Definition: APIMath.h:316
Vector3 operator-(const Vector3 &rhv) const
Definition: APIMath.h:55
Real y
Definition: APIMath.h:41
Vector3 X
Definition: APIMath.h:425
void Set(int row, int col, Real data)
Definition: APIMath.h:262
ColorValue()
Definition: APIMath.h:191
Real Get(int row, int col) const
Definition: APIMath.h:228
Coordinate.
Definition: APIMath.h:416
Vector3(Real _x, Real _y, Real _z)
Definition: APIMath.h:48
int size() const
Definition: APIMath.h:140
Point or vector.
Definition: APIMath.h:16
Vector3 operator*(Real vv) const
Definition: APIMath.h:76
Real z
Definition: APIMath.h:42
Real y
Definition: APIMath.h:20
Point of vector list.
Definition: APIMath.h:131
Vector3 operator*(const Vector3 &rhv) const
Definition: APIMath.h:69
Vector3 minPt
Definition: APIMath.h:284
Quaternion(Real _w, Real _x, Real _y, Real _z)
Definition: APIMath.h:322
Real Get(int row, int col) const
Definition: APIMath.h:257
Vector3 GetSize() const
Definition: APIMath.h:294
Matrix3.
Definition: APIMath.h:218
ColorValue(float _r, float _g, float _b, float _a)
Definition: APIMath.h:196
Definition: APIMath.h:334
Vector3 operator/(Real vv) const
Definition: APIMath.h:83
Vector3Arr m_arr
Definition: APIMath.h:175
Real x
Definition: APIMath.h:40
Vector3Arr & GetImpl()
Definition: APIMath.h:172
static const Vector3 ZERO
Definition: APIMath.h:120
static const Vector3 UNIT_Y
Definition: APIMath.h:122
Quaternion()
Definition: APIMath.h:321
Definition: APIMath.h:338
Vector3 operator+(const Vector3 &rhv) const
Definition: APIMath.h:62
float b
Definition: APIMath.h:188
std::pair< bool, Real > RayResult
Definition: APIMath.h:356
static const Vector3 UNIT_X
Definition: APIMath.h:121
float r
Definition: APIMath.h:186
void resize(int nSize)
Definition: APIMath.h:164
Vector3 Z
Definition: APIMath.h:427
Matrix4()
Definition: APIMath.h:253
long AsRGB() const
Definition: APIMath.h:207
Vector2()
Definition: APIMath.h:22
void clear()
Definition: APIMath.h:169
EnumEularSequence
Definition: APIMath.h:331
const Vector3 & getDirection(void) const
Definition: APIMath.h:387
Vector3 mOrigin
Definition: APIMath.h:405
AABox()
Definition: APIMath.h:287
const Vector3Arr & GetImpl() const
Definition: APIMath.h:171
Ray(const Vector3 &origin, const Vector3 &direction)
Definition: APIMath.h:368
Vector3 GetCenter() const
Definition: APIMath.h:296
ColorValue(int _r, int _g, int _b, int _a=255)
Definition: APIMath.h:201
Point or vector.
Definition: APIMath.h:37
Matrix3()
Definition: APIMath.h:224
Real x
Definition: APIMath.h:19
Vector3 Origion
Definition: APIMath.h:424
Definition: APIMath.h:335
AABox(const Vector3 &_minPt, const Vector3 &_maxPt)
Definition: APIMath.h:288
Vector3 mDirection
Definition: APIMath.h:406
Real y
Definition: APIMath.h:318
std::vector< Vector2 > Vector2List
Definition: APIMath.h:30
Definition: APIMath.h:337
float a
Definition: APIMath.h:189
Color Value.
Definition: APIMath.h:183
std::vector< Vector3 > Vector3Arr
Definition: APIMath.h:134
Definition: APIMath.h:336
void setOrigin(const Vector3 &origin)
Definition: APIMath.h:374
const Vector3 & getOrigin(void) const
Definition: APIMath.h:378
double Real
Definition: APIMath.h:7
void Set(int row, int col, Real data)
Definition: APIMath.h:233