Aleph-w 3.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 <gsl/gsl_rng.h>
34# include <gsl/gsl_randist.h>
35# include <iostream>
36# include <limits>
37# include <eepicgeom.H>
38
40
41# include <ctime>
42using namespace std;
43
44 // construye un poligono aleatorio de n lados cuyos puntos no sobrepasan
45 // los extremos actuales del plano
47 double min_x, double max_x,
48 double min_y, double max_y)
49{
51 gsl_rng_set(r, std::time(NULL) % gsl_rng_max(r));
52
53 again:
54
55 {
56 Polygon poly;
57
58 for (int i = 0; i < n; ++i)
59 {
60
61 retry:
62
63 try
64 {
65 cout << "Generating point " << i << endl;
66
67 const Geom_Number x = gsl_ran_flat(r, min_x, max_x);
68 const Geom_Number y = gsl_ran_flat(r, min_y, max_y);
69
70 cout << Point(x, y).to_string() << " triying ..." << endl;
71
72 poly.add_vertex(Point(x, y));
73
74 cout << "success" << endl;
75 }
76 catch (domain_error)
77 {
78 cout << " crosses" << endl;
79 goto retry;
80 }
81 }
82
83 cout << "closing ..." << endl;
84
85 try
86 {
87 poly.close();
88
89 cout << "Finished polygon generation" << endl;
90
92
93 return poly;
94 }
95 catch (domain_error)
96 {
97 cout << " close crosses" << endl;
98
99 goto again;
100 }
101 }
102}
103
104
105int main()
106{
107 Segment sg0(Point(232, 438), Point(1227, 2183));
108 Segment sg1(Point(162, 1838), Point(327, 883));
109 Segment sg2(Point(16, 38), Point(827, 783));
110 Segment sg3(Point(1000, 1500), Point(10, 183));
111 Segment sg4(Point(200, 300), Point(-800, 1600));
112 Segment sg5(Point(0, 1400), Point(1800, 0));
113
114 Segment s1(Point(0, 0), Point(0, 1400));
115 Segment s2(Point(0, 1400), Point(2800, 1400));
116
117 Point p1 = sg4.intersection_with(sg5);
118
119 Triangle tr(Point(-1632, 237), Point(737, 235), Point(272, 1772));
120
121 Triangle tr1(Point(0, 0), Point(600, 600), Point(800, 0));
122
123 Ellipse el(Point(-800, 600), 800, 330);
124
125 Point pt(400 + 700, 400 + 100);
126
127# ifdef nada
128 if (el.contains_to(pt))
129 cout << "El punto de prueba " << pt.to_string()
130 << " está dentro de la elipse de centro "
131 << el.get_center().to_string() << endl
132 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
133 << endl;
134 else
135 cout << "Falló prueba de inclusión del punto " << pt.to_string()
136 << " en elipse de centro "
137 << el.get_center().to_string() << endl
138 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
139 << endl;
140
141 char c;
142
143 cin >> c;
144# endif
145
146 Eepic_Plane plane(2000, 2000);
147
148 put_in_plane(plane, pt);
149
150 put_in_plane(plane, Arrow(s1));
151 put_in_plane(plane, s2);
152
153 put_in_plane(plane, p1);
154
155 put_in_plane(plane, sg4);
156 put_in_plane(plane, sg5);
157
158 put_in_plane(plane, sg1);
159 put_in_plane(plane, sg2);
160 put_in_plane(plane, sg3);
161
162 put_in_plane(plane, tr);
163 put_in_plane(plane, tr1);
164 put_in_plane(plane, el);
165
167
168 Segment ts1, ts2;
169
170 el.compute_tangents(ts1, ts2, 3.25);
171
172 put_in_plane(plane, Arrow(ts1));
173 put_in_plane(plane, ts2);
174
175 Segment par(ts1, 100);
176
177 put_in_plane(plane, Arrow(par));
178
179 Segment seg (Point(4,0), Point(-300, 400));
181
182 put_in_plane(plane, inter);
183
184 put_in_plane(plane, inter.get_src_point());
185 put_in_plane(plane, inter.get_tgt_point());
186
187# ifdef nada
188 put_in_plane(plane,
189 Text(sg0.get_tgt_point(),
190 gnu::autosprintf("m0 = %.2f", sg0.slope())));
191 put_in_plane(plane, Arrow(sg0));
192
193 put_in_plane(plane,
194 Text(sg1.get_tgt_point(),
195 gnu::autosprintf("m1 = %.2f", sg1.slope())));
196 put_in_plane(plane, Arrow(sg1));
197
198 put_in_plane(plane,
199 Text(sg2.get_tgt_point(),
200 gnu::autosprintf("m2 = %.2f", sg2.slope())));
201 put_in_plane(plane, Arrow(sg2));
202
203 put_in_plane(plane,
204 Text(sg3.get_tgt_point(),
205 gnu::autosprintf("m3 = %.2f", sg3.slope())));
206 put_in_plane(plane, Arrow(sg3));
207
208 put_in_plane(plane,
209 Text(sg4.get_tgt_point(),
210 gnu::autosprintf("m4 = %.2f", sg4.slope())));
211 put_in_plane(plane, Arrow(sg4));
212# endif
213 // put_in_plane(plane, seg);
214 // put_in_plane(plane, inter);
215
216 // put_in_plane(plane, Arrow(Point(20, 20), Point(400, 500)));
217
218 // put_in_plane(plane, Thick_Segment(Point(19,100), Point(582, 267)));
219
220 // put_in_plane(plane, Thick_Arrow(Point(19,100), Point(82, 267)));
221
222 // put_in_plane(plane, Dotted_Segment(Point(190, 100), Point(820, 267)));
223
224 // put_in_plane(plane, Dash_Segment(Point(200, 190), Point(267, 420)));
225
226 // put_in_plane(plane, Arrow_Dash_Segment(Point(267, 820), Point(10,190)));
227
228 // put_in_plane(plane, Arrow_Dotted_Segment(Point(67, 20), Point(100,190)));
229
230 // plane.compute_extreme_points();
231
232 Polygon poly = make_random_polygon(13, 0, 2000, 0, 1400);
233
234 // put_in_plane(plane, Spline(poly));
235
236 // put_in_plane(plane, Spline_Arrow(poly));
237
238 // put_in_plane(plane, Polygon_With_Arrows(poly));
239
240 put_in_plane(plane, poly);
241
242 // put_in_plane(plane, Shade_Polygon(poly));
243
244 // put_in_plane(plane, Regular_Polygon(Point(0, 0), 400, 12, PI/3));
245
246 // put_in_plane(plane, Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
247
248 // put_in_plane(plane, Dotted_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
249
250 // put_in_plane(plane, Dash_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
251
252 // put_in_plane(plane,
253 // Dotted_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
254
255 // put_in_plane(plane,
256 // Dash_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
257
258 // put_in_plane(plane, Shade_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
259
260 // put_in_plane(plane,
261 // Shade_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
262
263 // put_in_plane(plane,
264 // Shade_Regular_Polygon_With_Arrows(Point(0, 0), 400, 12, PI/3));
265
266 // put_in_plane(plane, Eepic_Spline(Point(-100, -200), 400, 7, PI/3));
267
268 Regular_Polygon reg_poly(Point(200, 790), 300, 5);
269
270 // put_in_plane(plane, reg_poly);
271
272 // Polygon p(reg_poly);
273
274 // put_in_plane(plane, Polygon(p));
275
276 Segment linea1(Point(100, 100), Point(400, 200));
277
279
280 put_in_plane(plane, Arrow(linea1));
281
283
284 put_in_plane(plane, perp1.get_src_point());
285
286 put_in_plane(plane, perp1.get_tgt_point());
287
288 Segment linea2(Point(100, 100), Point(400, -200));
289
291
292 put_in_plane(plane, Arrow(linea2));
293
295
296 put_in_plane(plane, perp2.get_src_point());
297
298 put_in_plane(plane, perp2.get_tgt_point());
299
300 Segment linea3(Point(100, 100), Point(-400, -200));
301
303
304 put_in_plane(plane, Arrow(linea3));
305
307
308 put_in_plane(plane, perp3.get_src_point());
309
310 put_in_plane(plane, perp3.get_tgt_point());
311
312 Segment linea4(Point(100, 100), Point(-400, 200));
313
315
316 put_in_plane(plane, Arrow(linea4));
317
319
320 put_in_plane(plane, perp4.get_src_point());
321
322 put_in_plane(plane, perp4.get_tgt_point());
323
324 // put_in_plane(plane, Spline(Regular_Polygon(Point(-300, -300), 300, 4)));
325
326 // put_in_plane(plane, Spline_Arrow(Regular_Polygon(Point(-300, 300), 300, 4)));
327
329
330 put_in_plane(plane, Ellipse(Point(-100, -100), 200, 100));
331
332 // put_in_plane(plane, Shade_Ellipse(el));
333
334 ofstream output1("test-1.eepic", ios::trunc);
335
336 plane.put_cartesian_axis();
337
338 plane.draw(output1);
339
340 ofstream output2("test-2.eepic", ios::trunc);
341
342 plane.zoom(0.25);
343 plane.draw(output2);
344
345
346}
An axis-aligned ellipse.
Definition point.H:2076
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:678
void close()
Close the polygon.
Definition polygon.H:843
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:1135
Represents a line segment between two points.
Definition point.H:837
Point intersection_with(const Segment &s) const
Computes the intersection point of the infinite lines defined by two segments.
Definition point.H:1334
Segment mid_perpendicular(const Geom_Number &dist) const
Returns the perpendicular chord of a given length passing through the midpoint.
Definition point.H:1225
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.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
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_rng * r
ofstream output2
Definition writeJoin.C:230
ofstream output1
Definition writeJoin.C:229