Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
test_eepicgeom.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the "Software"), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
20
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
23
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31*/
32
33# include <ah-random.H>
34# include <iostream>
35# include <limits>
36# include <eepicgeom.H>
37
39
40# include <ctime>
41using namespace std;
42
43 // construye un poligono aleatorio de n lados cuyos puntos no sobrepasan
44 // los extremos actuales del plano
46 double min_x, double max_x,
47 double min_y, double max_y)
48{
49 Gsl_Compatible_Rng r(std::time(NULL) % Gsl_Compatible_Rng::max());
50
51 again:
52
53 {
54 Polygon poly;
55
56 for (int i = 0; i < n; ++i)
57 {
58
59 retry:
60
61 try
62 {
63 cout << "Generating point " << i << endl;
64
65 const Geom_Number x = r.flat(min_x, max_x);
66 const Geom_Number y = r.flat(min_y, max_y);
67
68 cout << Point(x, y).to_string() << " triying ..." << endl;
69
70 poly.add_vertex(Point(x, y));
71
72 cout << "success" << endl;
73 }
74 catch (domain_error)
75 {
76 cout << " crosses" << endl;
77 goto retry;
78 }
79 }
80
81 cout << "closing ..." << endl;
82
83 try
84 {
85 poly.close();
86
87 cout << "Finished polygon generation" << endl;
88
89
90 return poly;
91 }
92 catch (domain_error)
93 {
94 cout << " close crosses" << endl;
95
96 goto again;
97 }
98 }
99}
100
101
102int main()
103{
104 Segment sg0(Point(232, 438), Point(1227, 2183));
105 Segment sg1(Point(162, 1838), Point(327, 883));
106 Segment sg2(Point(16, 38), Point(827, 783));
107 Segment sg3(Point(1000, 1500), Point(10, 183));
108 Segment sg4(Point(200, 300), Point(-800, 1600));
109 Segment sg5(Point(0, 1400), Point(1800, 0));
110
111 Segment s1(Point(0, 0), Point(0, 1400));
112 Segment s2(Point(0, 1400), Point(2800, 1400));
113
114 Point p1 = sg4.intersection_with(sg5);
115
116 Triangle tr(Point(-1632, 237), Point(737, 235), Point(272, 1772));
117
118 Triangle tr1(Point(0, 0), Point(600, 600), Point(800, 0));
119
120 Ellipse el(Point(-800, 600), 800, 330);
121
122 Point pt(400 + 700, 400 + 100);
123
124# ifdef nada
125 if (el.contains_to(pt))
126 cout << "El punto de prueba " << pt.to_string()
127 << " está dentro de la elipse de centro "
128 << el.get_center().to_string() << endl
129 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
130 << endl;
131 else
132 cout << "Falló prueba de inclusión del punto " << pt.to_string()
133 << " en elipse de centro "
134 << el.get_center().to_string() << endl
135 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
136 << endl;
137
138 char c;
139
140 cin >> c;
141# endif
142
143 Eepic_Plane plane(2000, 2000);
144
145 put_in_plane(plane, pt);
146
147 put_in_plane(plane, Arrow(s1));
148 put_in_plane(plane, s2);
149
150 put_in_plane(plane, p1);
151
152 put_in_plane(plane, sg4);
153 put_in_plane(plane, sg5);
154
155 put_in_plane(plane, sg1);
156 put_in_plane(plane, sg2);
157 put_in_plane(plane, sg3);
158
159 put_in_plane(plane, tr);
160 put_in_plane(plane, tr1);
161 put_in_plane(plane, el);
162
163 Segment si = sg4.intersection_with(tr);
164
165 Segment ts1, ts2;
166
167 el.compute_tangents(ts1, ts2, 3.25);
168
169 put_in_plane(plane, Arrow(ts1));
170 put_in_plane(plane, ts2);
171
172 Segment par(ts1, 100);
173
174 put_in_plane(plane, Arrow(par));
175
176 Segment seg (Point(4,0), Point(-300, 400));
177 Segment inter = el.intersection_with(seg);
178
179 put_in_plane(plane, inter);
180
181 put_in_plane(plane, inter.get_src_point());
182 put_in_plane(plane, inter.get_tgt_point());
183
184# ifdef nada
185 put_in_plane(plane,
186 Text(sg0.get_tgt_point(),
187 gnu::autosprintf("m0 = %.2f", sg0.slope())));
188 put_in_plane(plane, Arrow(sg0));
189
190 put_in_plane(plane,
191 Text(sg1.get_tgt_point(),
192 gnu::autosprintf("m1 = %.2f", sg1.slope())));
193 put_in_plane(plane, Arrow(sg1));
194
195 put_in_plane(plane,
196 Text(sg2.get_tgt_point(),
197 gnu::autosprintf("m2 = %.2f", sg2.slope())));
198 put_in_plane(plane, Arrow(sg2));
199
200 put_in_plane(plane,
201 Text(sg3.get_tgt_point(),
202 gnu::autosprintf("m3 = %.2f", sg3.slope())));
203 put_in_plane(plane, Arrow(sg3));
204
205 put_in_plane(plane,
206 Text(sg4.get_tgt_point(),
207 gnu::autosprintf("m4 = %.2f", sg4.slope())));
208 put_in_plane(plane, Arrow(sg4));
209# endif
210 // put_in_plane(plane, seg);
211 // put_in_plane(plane, inter);
212
213 // put_in_plane(plane, Arrow(Point(20, 20), Point(400, 500)));
214
215 // put_in_plane(plane, Thick_Segment(Point(19,100), Point(582, 267)));
216
217 // put_in_plane(plane, Thick_Arrow(Point(19,100), Point(82, 267)));
218
219 // put_in_plane(plane, Dotted_Segment(Point(190, 100), Point(820, 267)));
220
221 // put_in_plane(plane, Dash_Segment(Point(200, 190), Point(267, 420)));
222
223 // put_in_plane(plane, Arrow_Dash_Segment(Point(267, 820), Point(10,190)));
224
225 // put_in_plane(plane, Arrow_Dotted_Segment(Point(67, 20), Point(100,190)));
226
227 // plane.compute_extreme_points();
228
229 Polygon poly = make_random_polygon(13, 0, 2000, 0, 1400);
230
231 // put_in_plane(plane, Spline(poly));
232
233 // put_in_plane(plane, Spline_Arrow(poly));
234
235 // put_in_plane(plane, Polygon_With_Arrows(poly));
236
237 put_in_plane(plane, poly);
238
239 // put_in_plane(plane, Shade_Polygon(poly));
240
241 // put_in_plane(plane, Regular_Polygon(Point(0, 0), 400, 12, PI/3));
242
243 // put_in_plane(plane, Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
244
245 // put_in_plane(plane, Dotted_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
246
247 // put_in_plane(plane, Dash_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
248
249 // put_in_plane(plane,
250 // Dotted_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
251
252 // put_in_plane(plane,
253 // Dash_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
254
255 // put_in_plane(plane, Shade_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
256
257 // put_in_plane(plane,
258 // Shade_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
259
260 // put_in_plane(plane,
261 // Shade_Regular_Polygon_With_Arrows(Point(0, 0), 400, 12, PI/3));
262
263 // put_in_plane(plane, Eepic_Spline(Point(-100, -200), 400, 7, PI/3));
264
265 Regular_Polygon reg_poly(Point(200, 790), 300, 5);
266
267 // put_in_plane(plane, reg_poly);
268
269 // Polygon p(reg_poly);
270
271 // put_in_plane(plane, Polygon(p));
272
273 Segment linea1(Point(100, 100), Point(400, 200));
274
275 Segment perp1 = linea1.mid_perpendicular(linea1.size()/6);
276
277 put_in_plane(plane, Arrow(linea1));
278
279 put_in_plane(plane, Thick_Arrow(perp1));
280
281 put_in_plane(plane, perp1.get_src_point());
282
283 put_in_plane(plane, perp1.get_tgt_point());
284
285 Segment linea2(Point(100, 100), Point(400, -200));
286
287 Segment perp2 = linea2.mid_perpendicular(linea2.size()/6);
288
289 put_in_plane(plane, Arrow(linea2));
290
291 put_in_plane(plane, Thick_Arrow(perp2));
292
293 put_in_plane(plane, perp2.get_src_point());
294
295 put_in_plane(plane, perp2.get_tgt_point());
296
297 Segment linea3(Point(100, 100), Point(-400, -200));
298
299 Segment perp3 = linea3.mid_perpendicular(linea3.size()/6);
300
301 put_in_plane(plane, Arrow(linea3));
302
303 put_in_plane(plane, Thick_Arrow(perp3));
304
305 put_in_plane(plane, perp3.get_src_point());
306
307 put_in_plane(plane, perp3.get_tgt_point());
308
309 Segment linea4(Point(100, 100), Point(-400, 200));
310
311 Segment perp4 = linea4.mid_perpendicular(linea4.size()/6);
312
313 put_in_plane(plane, Arrow(linea4));
314
315 put_in_plane(plane, Thick_Arrow(perp4));
316
317 put_in_plane(plane, perp4.get_src_point());
318
319 put_in_plane(plane, perp4.get_tgt_point());
320
321 // put_in_plane(plane, Spline(Regular_Polygon(Point(-300, -300), 300, 4)));
322
323 // put_in_plane(plane, Spline_Arrow(Regular_Polygon(Point(-300, 300), 300, 4)));
324
325 put_in_plane(plane, Polygon(reg_poly));
326
327 put_in_plane(plane, Ellipse(Point(-100, -100), 200, 100));
328
329 // put_in_plane(plane, Shade_Ellipse(el));
330
331 ofstream output1("test-1.eepic", ios::trunc);
332
333 plane.put_cartesian_axis();
334
335 plane.draw(output1);
336
337 ofstream output2("test-2.eepic", ios::trunc);
338
339 plane.zoom(0.25);
340 plane.draw(output2);
341
342
343}
The random number generators of Aleph: the one that gives the numbers of the gsl_rng_mt19937 of GSL,...
An axis-aligned ellipse.
Definition point.H:2076
const Geom_Number & get_vradius() const
Gets the vertical radius.
Definition point.H:2153
void compute_tangents(Segment &s1, Segment &s2, const Geom_Number &m) const
Computes the two tangent segments to this ellipse with a given slope.
Definition point.H:2263
const Point & get_center() const
Gets the center point of the ellipse.
Definition point.H:2143
bool contains_to(const Point &p) const
Definition point.H:2369
const Geom_Number & get_hradius() const
Gets the horizontal radius.
Definition point.H:2148
Segment intersection_with(const Segment &sg) const
Computes the intersection segment between a line segment and this ellipse.
Definition point.H:2391
A random number generator with the sequences of GSL's gsl_rng_mt19937.
Definition ah-random.H:147
static constexpr result_type max() noexcept
The greatest number of operator()(): 2^32 - 1.
Definition ah-random.H:259
double flat(const double a, const double b) noexcept
A real number of the uniform distribution on [a, b), as gsl_ran_flat(r, a, b).
Definition ah-random.H:358
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:221
std::string to_string() const
Returns a string representation of the point as "(x,y)".
Definition point.H:640
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:247
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:686
void close()
Close the polygon.
Definition polygon.H:851
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:1143
Represents a line segment between two points.
Definition point.H:837
double slope() const
Returns the slope of the segment.
Definition point.H:1012
Point intersection_with(const Segment &s) const
Computes the intersection point of the infinite lines defined by two segments.
Definition point.H:1334
Geom_Number size() const
Definition point.H:1075
Segment mid_perpendicular(const Geom_Number &dist) const
Returns the perpendicular chord of a given length passing through the midpoint.
Definition point.H:1225
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
Definition point.H:933
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Definition point.H:924
Represents a text string positioned at a 2D point.
Definition point.H:2817
A non-degenerate triangle defined by three points.
Definition point.H:1512
2D canvas for generating EEPIC/LaTeX picture environments.
Definition eepicgeom.H:250
void zoom(const double &factor)
Scale the EEPIC plane in real points (zoom in/out).
Definition eepicgeom.H:397
void put_cartesian_axis()
Enable drawing Cartesian axes when calling draw().
Definition eepicgeom.H:573
void draw(std::ostream &output, const bool &squarize=true)
Emits a complete LaTeX picture environment containing the geometric objects.
Definition eepicgeom.H:484
EEPIC/LaTeX geometric drawing utilities.
static mpfr_t y
Definition mpfr_mul_d.c:3
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
Definition tikzgeom.H:1511
STL namespace.
bool tiny_keys
Global flag to enable tiny font size for keys/labels.
Polygon make_random_polygon(const size_t &n, double min_x, double max_x, double min_y, double max_y)
int main()
Gsl_Compatible_Rng r
ofstream output2
Definition writeJoin.C:230
ofstream output1
Definition writeJoin.C:229