Point3D.h
Go to the documentation of this file.
1 // Point3D.h: interface for the CPoint3D class.
2 //
4 
5 #pragma once
6 #include <math.h>
7 #define _USE_MATH_DEFINES
8 #include <ostream>
9 using namespace std;
10 
11 struct CPoint3D
12 {
13 public:
14  double x, y, z;
15  CPoint3D();
16  CPoint3D(double x, double y, double z);
17  inline CPoint3D& operator +=(const CPoint3D& pt);
18  inline CPoint3D& operator -=(const CPoint3D& pt);
19  inline CPoint3D& operator *=(double times);
20  inline CPoint3D& operator /=(double times);
21  inline CPoint3D Rotate() const;
22  inline double Len() const;
23  inline void Normalize();
24  bool operator==(const CPoint3D& other) const
25  {
26  return x == other.x && y == other.y && z == other.z;
27  }
28  bool operator<(const CPoint3D& other) const
29  {
30  if (x < other.x)
31  return true;
32  else if (x > other.x)
33  return false;
34  else if (y < other.y)
35  return true;
36  else if (y > other.y)
37  return false;
38  else if (z < other.z)
39  return true;
40  else if (z > other.z)
41  return false;
42  return false;
43  }
44  friend ostream& operator<<(ostream& out, const CPoint3D& pt)
45  {
46  out << pt.x << " " << pt.y << " " << pt.z << endl;
47  return out;
48  }
49 };
51 {
52  return CPoint3D(z, x, y);
53 }
54 
56 {
57  x += pt.x;
58  y += pt.y;
59  z += pt.z;
60  return *this;
61 }
62 
64 {
65  x -= pt.x;
66  y -= pt.y;
67  z -= pt.z;
68  return *this;
69 }
70 
72 {
73  x *= times;
74  y *= times;
75  z *= times;
76  return *this;
77 }
78 
80 {
81  x /= times;
82  y /= times;
83  z /= times;
84  return *this;
85 }
86 
87 double CPoint3D::Len() const
88 {
89  return sqrt(x * x + y * y + z * z);
90 }
91 
93 {
94  double len = Len();
95  x /= len;
96  y /= len;
97  z /= len;
98 }
99 
100 CPoint3D operator +(const CPoint3D& pt1, const CPoint3D& pt2);
101 CPoint3D operator -(const CPoint3D& pt1, const CPoint3D& pt2);
102 CPoint3D operator *(const CPoint3D& pt, double times);
103 CPoint3D operator /(const CPoint3D& pt, double times);
104 CPoint3D operator *(double times, const CPoint3D& pt);
105 CPoint3D operator *(const CPoint3D& pt1, const CPoint3D& pt2);
106 CPoint3D VectorCross(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3);
107 double operator ^(const CPoint3D& pt1, const CPoint3D& pt2);
108 double GetTriangleArea(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3);
109 double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2);
110 double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3);
111 void VectorCross(const float* u, const float* v, float * n);
112 float VectorDot(const float* u, const float* v);
113 float AngleBetween(const float* u, const float* v);
114 CPoint3D CombinePointAndNormalTo(const CPoint3D& pt, const CPoint3D& normal);
115 CPoint3D CombineTwoNormalsTo(const CPoint3D& pt1, double coef1, const CPoint3D& pt2, double coef2);
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator*=(half &a, const half &b)
Definition: Half.h:228
double x
Definition: Point3D.h:14
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator-=(half &a, const half &b)
Definition: Half.h:232
double AngleBetween(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:59
CPoint3D VectorCross(const CPoint3D &pt1, const CPoint3D &pt2, const CPoint3D &pt3)
Definition: Point3D.cpp:43
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
CPoint3D Rotate() const
Definition: Point3D.h:50
double y
Definition: Point3D.h:14
double Len() const
Definition: Point3D.h:87
bool operator==(const CPoint3D &other) const
Definition: Point3D.h:24
friend ostream & operator<<(ostream &out, const CPoint3D &pt)
Definition: Point3D.h:44
double operator^(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:48
float VectorDot(const float *u, const float *v)
Definition: Point3D.cpp:89
double GetTriangleArea(const CPoint3D &pt1, const CPoint3D &pt2, const CPoint3D &pt3)
Definition: Point3D.cpp:53
CPoint3D & operator*=(double times)
Definition: Point3D.h:71
CPoint3D & operator+=(const CPoint3D &pt)
Definition: Point3D.h:55
CPoint3D operator/(const CPoint3D &pt, double times)
Definition: Point3D.cpp:26
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator+=(half &a, const half &b)
Definition: Half.h:224
bool operator<(const CPoint3D &other) const
Definition: Point3D.h:28
CPoint3D CombineTwoNormalsTo(const CPoint3D &pt1, double coef1, const CPoint3D &pt2, double coef2)
Definition: Point3D.cpp:118
CPoint3D & operator-=(const CPoint3D &pt)
Definition: Point3D.h:63
CPoint3D operator*(const CPoint3D &pt, double times)
Definition: Point3D.cpp:21
CPoint3D CombinePointAndNormalTo(const CPoint3D &pt, const CPoint3D &normal)
Definition: Point3D.cpp:113
CPoint3D & operator/=(double times)
Definition: Point3D.h:79
CPoint3D operator-(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:16
CPoint3D operator+(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:11
double z
Definition: Point3D.h:14
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half & operator/=(half &a, const half &b)
Definition: Half.h:236
void Normalize()
Definition: Point3D.h:92


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:47