-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLine.h
143 lines (107 loc) · 3.3 KB
/
Line.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// Created by Ryan.Zurrin001 on 12/16/2021.
//
#ifndef PHYSICSFORMULA_LINE_H
#define PHYSICSFORMULA_LINE_H
#include "Vector.h"
#include "Point.h"
namespace rez {
class Line {
Vector3f dir; // Normalized direction vector.
Point3d point_in_line;
public:
Line() {}
Line(Point3d& p1, Point3d& p2)
{
point_in_line = p1;
dir = p2 - p1;
dir.normalize();
}
void setDirection(Vector3f&);
void setPoint(Point3d&);
[[nodiscard]] Vector3f direction() const;
[[nodiscard]] Point3d point() const;
};
class Line2d {
Vector2f dir;
Point2d point_in_line;
Vector2f normal_vec;
public:
Line2d() {}
Line2d(Point2d& p1, Vector2f& _dir)
{
point_in_line = p1;
dir = _dir;
dir.normalize();
normal_vec.assign(X_, -dir[Y_]);
normal_vec.assign(Y_, dir[X_]);
}
[[nodiscard]] Vector2f direction() const;
[[nodiscard]] Point2d point() const;
[[nodiscard]] Vector2f normal() const;
};
template<class coord_type, size_t dim = DIM3>
class LineStd {
Vector<coord_type, dim> point;
Vector<coord_type, dim> dir;
Vector<coord_type, dim> second;
float d{};
public:
LineStd() {}
LineStd(Vector<coord_type, dim>& p1, Vector<coord_type, dim>& p2, bool points = false) {
if (points) {
dir = p2 - p1;
second = p2;
}
else
dir = p2;
dir.normalize();
point = p1;
}
Vector<coord_type, dim> getPoint() const;
Vector<coord_type, dim> getSecondPoint() const;
Vector<coord_type, dim> getDir() const;
[[nodiscard]] float getD() const;
void setDirection(Vector<coord_type, dim>& _dir);
void setPoint(Vector<coord_type, dim>& _point);
void setD(float value);
};
template<class coord_type, size_t dim>
inline Vector<coord_type, dim> LineStd<coord_type, dim>::getPoint()const
{
return point;
}
template<class coord_type, size_t dim>
inline Vector<coord_type, dim> LineStd<coord_type, dim>::getSecondPoint() const
{
return second;
}
template<class coord_type, size_t dim>
inline Vector<coord_type, dim> LineStd<coord_type, dim>::getDir() const
{
return dir;
}
template<class coord_type, size_t dim>
inline float LineStd<coord_type, dim>::getD() const
{
return d;
}
template<class coord_type, size_t dim>
inline void LineStd<coord_type, dim>::setDirection(Vector<coord_type, dim>& _dir)
{
dir = _dir;
}
template<class coord_type, size_t dim>
inline void LineStd<coord_type, dim>::setPoint(Vector<coord_type, dim>& _point)
{
point = _point;
}
template<class coord_type, size_t dim>
inline void LineStd<coord_type, dim>::setD(float value)
{
d = value;
}
typedef LineStd<float, DIM2> Line2dStd;
typedef LineStd<float, DIM3> Line3dStd;
}
#endif //PHYSICSFORMULA_LINE_H