/Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/Triangle2D.hxx Source File

Clothoids: /Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/Triangle2D.hxx Source File
Clothoids
Triangle2D.hxx
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2017 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Universita` degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
23
24namespace G2lib {
25
26 /*\
27 | _____ _ _ ____ ____
28 | |_ _| __(_) __ _ _ __ __ _| | ___|___ \| _ \
29 | | || '__| |/ _` | '_ \ / _` | |/ _ \ __) | | | |
30 | | || | | | (_| | | | | (_| | | __// __/| |_| |
31 | |_||_| |_|\__,_|_| |_|\__, |_|\___|_____|____/
32 | |___/
33 \*/
37 class Triangle2D {
38 real_type m_p1[2], m_p2[2], m_p3[2];
39 real_type m_s0;
40 real_type m_s1;
41 integer m_icurve;
42
43 public:
44
45 Triangle2D( Triangle2D const & t )
46 { *this = t; }
47
48 Triangle2D( ) {
49 m_p1[0] = m_p1[1] = m_p2[0] = m_p2[1] = m_p3[0] = m_p3[1] = 0;
50 m_s0 = 0;
51 m_s1 = 0;
52 m_icurve = 0;
53 }
54
56 real_type x1, real_type y1,
57 real_type x2, real_type y2,
58 real_type x3, real_type y3,
59 real_type s0, real_type s1,
60 integer icurve
61 ) {
62 m_p1[0] = x1; m_p1[1] = y1;
63 m_p2[0] = x2; m_p2[1] = y2;
64 m_p3[0] = x3; m_p3[1] = y3;
65 m_s0 = s0;
66 m_s1 = s1;
67 m_icurve = icurve;
68 }
69
71 real_type const p1[2],
72 real_type const p2[2],
73 real_type const p3[2],
74 real_type s0,
75 real_type s1,
76 integer icurve
77 ) {
78 m_p1[0] = p1[0]; m_p1[1] = p1[1];
79 m_p2[0] = p2[0]; m_p2[1] = p2[1];
80 m_p3[0] = p3[0]; m_p3[1] = p3[1];
81 m_s0 = s0;
82 m_s1 = s1;
83 m_icurve = icurve;
84 }
85
86 ~Triangle2D() {}
87
88 Triangle2D const &
89 operator = ( Triangle2D const & t ) {
90 m_p1[0] = t.m_p1[0]; m_p1[1] = t.m_p1[1];
91 m_p2[0] = t.m_p2[0]; m_p2[1] = t.m_p2[1];
92 m_p3[0] = t.m_p3[0]; m_p3[1] = t.m_p3[1];
93 m_s0 = t.m_s0;
94 m_s1 = t.m_s1;
95 m_icurve = t.m_icurve;
96 return *this;
97 }
98
99 void
100 build(
101 real_type const p1[2],
102 real_type const p2[2],
103 real_type const p3[2],
104 real_type s0,
105 real_type s1,
106 integer icurve
107 ) {
108 m_p1[0] = p1[0]; m_p1[1] = p1[1];
109 m_p2[0] = p2[0]; m_p2[1] = p2[1];
110 m_p3[0] = p3[0]; m_p3[1] = p3[1];
111 m_s0 = s0;
112 m_s1 = s1;
113 m_icurve = icurve;
114 }
115
116 void
117 build(
118 real_type x1, real_type y1,
119 real_type x2, real_type y2,
120 real_type x3, real_type y3,
121 real_type s0,
122 real_type s1,
123 integer icurve
124 ) {
125 m_p1[0] = x1; m_p1[1] = y1;
126 m_p2[0] = x2; m_p2[1] = y2;
127 m_p3[0] = x3; m_p3[1] = y3;
128 m_s0 = s0;
129 m_s1 = s1;
130 m_icurve = icurve;
131 }
132
133 integer Icurve() const { return m_icurve; }
134
135 real_type x1() const { return m_p1[0]; }
136 real_type y1() const { return m_p1[1]; }
137
138 real_type x2() const { return m_p2[0]; }
139 real_type y2() const { return m_p2[1]; }
140
141 real_type x3() const { return m_p3[0]; }
142 real_type y3() const { return m_p3[1]; }
143
144 real_type S0() const { return m_s0; }
145 real_type S1() const { return m_s1; }
146
147 void
148 translate( real_type tx, real_type ty ) {
149 m_p1[0] += tx; m_p2[0] += tx; m_p3[0] += tx;
150 m_p1[1] += ty; m_p2[1] += ty; m_p3[1] += ty;
151 }
152
153 void
154 rotate( real_type angle, real_type cx, real_type cy );
155
156 void
157 scale( real_type sc ) {
158 m_p1[0] *= sc; m_p1[1] *= sc;
159 m_p2[0] *= sc; m_p2[1] *= sc;
160 m_p3[0] *= sc; m_p3[1] *= sc;
161 }
162
163 void
164 bbox(
165 real_type & xmin, real_type & ymin,
166 real_type & xmax, real_type & ymax
167 ) const {
168 minmax3( m_p1[0], m_p2[0], m_p3[0], xmin, xmax );
169 minmax3( m_p1[1], m_p2[1], m_p3[1], ymin, ymax );
170 }
171
172 real_type baricenter_x() const { return (m_p1[0]+m_p2[0]+m_p3[0])/3; }
173 real_type baricenter_y() const { return (m_p1[1]+m_p2[1]+m_p3[1])/3; }
174
175 real_type const * P1() const { return m_p1; }
176 real_type const * P2() const { return m_p2; }
177 real_type const * P3() const { return m_p3; }
178
179 bool overlap( Triangle2D const & ) const;
180
186 integer
188 return G2lib::is_counter_clockwise( m_p1, m_p2, m_p3 );
189 }
190
196 integer
198 real_type const pt[2] = {x,y};
199 return is_point_in_triangle( pt, m_p1, m_p2, m_p3 );
200 }
201
202 integer
203 is_inside( real_type const pt[2] ) const {
204 return is_point_in_triangle( pt, m_p1, m_p2, m_p3 );
205 }
206
208 dist_min( real_type x, real_type y ) const;
209
211 dist_max( real_type x, real_type y ) const;
212
213 string info() const;
214
215 void
216 info( ostream_type & stream ) const
217 { stream << this->info(); }
218
219 friend
221 operator << ( ostream_type & stream, Triangle2D const & c );
222
223 };
224
225}
226
Definition Triangle2D.hxx:37
integer is_counter_clockwise() const
Definition Triangle2D.hxx:187
friend ostream_type & operator<<(ostream_type &stream, Triangle2D const &c)
Definition Triangle2D.cc:316
integer is_inside(real_type x, real_type y) const
Definition Triangle2D.hxx:197
Definition BBox.cc:42
std::basic_ostream< char > ostream_type
output streaming
Definition Clothoids.hh:78
integer is_point_in_triangle(real_type const point[], real_type const P1[], real_type const P2[], real_type const P3[])
integer is_counter_clockwise(real_type const P1[], real_type const P2[], real_type const P3[])
void minmax3(real_type a, real_type b, real_type c, real_type &vmin, real_type &vmax)
Definition G2lib.hxx:118
double real_type
real type number
Definition Clothoids.hh:79
int integer
integer type number
Definition Clothoids.hh:80