Point3D.cpp
Go to the documentation of this file.
1 #include "Point3D.h"
2 #include "Parameters.h"
4 {
5 }
6 
7 CPoint3D::CPoint3D(double x, double y, double z) : x(x), y(y), z(z)
8 {
9 }
10 
11 CPoint3D operator +(const CPoint3D& pt1, const CPoint3D& pt2)
12 {
13  return CPoint3D(pt1.x + pt2.x, pt1.y + pt2.y, pt1.z + pt2.z);
14 }
15 
16 CPoint3D operator -(const CPoint3D& pt1, const CPoint3D& pt2)
17 {
18  return CPoint3D(pt1.x - pt2.x, pt1.y - pt2.y, pt1.z - pt2.z);
19 }
20 
21 CPoint3D operator *(const CPoint3D& pt, double times)
22 {
23  return CPoint3D(pt.x * times, pt.y * times, pt.z * times);
24 }
25 
26 CPoint3D operator /(const CPoint3D& pt, double times)
27 {
28  return CPoint3D(pt.x / times, pt.y / times, pt.z / times);
29 }
30 
31 CPoint3D operator *(double times, const CPoint3D& pt)
32 {
33  return CPoint3D(pt.x * times, pt.y * times, pt.z * times);
34 }
35 
36 CPoint3D operator*(const CPoint3D& pt1, const CPoint3D& pt2)
37 {
38  return CPoint3D(pt1.y * pt2.z - pt1.z * pt2.y,
39  pt1.z * pt2.x - pt1.x * pt2.z,
40  pt1.x * pt2.y - pt1.y * pt2.x);
41 }
42 
43 CPoint3D VectorCross(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3)
44 {
45  return (pt2 - pt1) * (pt3 - pt2);
46 }
47 
48 double operator ^(const CPoint3D& pt1, const CPoint3D& pt2)
49 {
50  return pt1.x * pt2.x + pt1.y * pt2.y + pt1.z * pt2.z;
51 }
52 
53 double GetTriangleArea(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3)
54 {
55  CPoint3D crossProduct = (pt2 - pt1) * (pt3 - pt2);
56  return 0.5 * crossProduct.Len();
57 }
58 
59 double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2)
60 {
61  double cosAngle = (pt1 ^ pt2) / pt1.Len() / pt2.Len();
62  if (cosAngle >= 1)
63  {
64  cosAngle = 1;
65  }
66  else if (cosAngle <= -1)
67  {
68  cosAngle = -1;
69  }
70  return acos(cosAngle);
71 }
72 
73 double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3)
74 {
75  CPoint3D u = pt2 - pt1;
76  CPoint3D v = pt3 - pt2;
77  double cosAngle = (u ^ v) / u.Len() / v.Len();
78  if (cosAngle >= 1)
79  {
80  cosAngle = 1;
81  }
82  else if (cosAngle <= -1)
83  {
84  cosAngle = -1;
85  }
86  return acos(cosAngle);
87 }
88 
89 float VectorDot(const float* u, const float* v)
90 {
91  return u[0] * v[0] + u[1] * v[1] + u[2] * v[2];
92 }
93 
94 void VectorCross(const float* u, const float* v, float* n)
95 {
96  n[0] = u[1] * v[2] - u[2] * v[1];
97  n[1] = u[2] * v[0] - u[0] * v[2];
98  n[2] = u[0] * v[1] - u[1] * v[0];
99 }
100 
101 float AngleBetween(const float* u, const float* v)
102 {
103  float lenU = sqrt(u[0] * u[0] + u[1] * u[1] + u[2] * u[2]);
104  float lenV = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
105  float dot = VectorDot(u, v) / lenU / lenV;
106  if (dot < -1)
107  dot = -1.0;
108  if (dot > 1)
109  dot = 1.0;
110  return acos(dot);
111 }
112 
114 {
115  return pt + normal * RateOfNormalShift;
116 }
117 
118 CPoint3D CombineTwoNormalsTo(const CPoint3D& pt1, double coef1, const CPoint3D& pt2, double coef2)
119 {
120  return coef1 * pt1 + coef2 * pt2;
121 }
float VectorDot(const float *u, const float *v)
Definition: Point3D.cpp:89
double x
Definition: Point3D.h:14
CPoint3D operator*(const CPoint3D &pt, double times)
Definition: Point3D.cpp:21
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
CPoint3D VectorCross(const CPoint3D &pt1, const CPoint3D &pt2, const CPoint3D &pt3)
Definition: Point3D.cpp:43
double y
Definition: Point3D.h:14
double AngleBetween(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:59
double Len() const
Definition: Point3D.h:87
CPoint3D CombineTwoNormalsTo(const CPoint3D &pt1, double coef1, const CPoint3D &pt2, double coef2)
Definition: Point3D.cpp:118
EIGEN_DEVICE_FUNC const AcosReturnType acos() const
CPoint3D operator/(const CPoint3D &pt, double times)
Definition: Point3D.cpp:26
const double RateOfNormalShift
Definition: Parameters.h:1
double GetTriangleArea(const CPoint3D &pt1, const CPoint3D &pt2, const CPoint3D &pt3)
Definition: Point3D.cpp:53
CPoint3D CombinePointAndNormalTo(const CPoint3D &pt, const CPoint3D &normal)
Definition: Point3D.cpp:113
double z
Definition: Point3D.h:14
CPoint3D operator+(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:11
CPoint3D()
Definition: Point3D.cpp:3
double operator^(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:48
CPoint3D operator-(const CPoint3D &pt1, const CPoint3D &pt2)
Definition: Point3D.cpp:16


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