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 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <gsl/gsl_rng.h>
29# include <gsl/gsl_randist.h>
30# include <iostream>
31# include <limits>
32# include <eepicgeom.H>
33
35
36# include <ctime>
37using namespace std;
38
39 // construye un poligono aleatorio de n lados cuyos puntos no sobrepasan
40 // los extremos actuales del plano
42 double min_x, double max_x,
43 double min_y, double max_y)
44{
46 gsl_rng_set(r, std::time(NULL) % gsl_rng_max(r));
47
48 again:
49
50 {
51 Polygon poly;
52
53 for (int i = 0; i < n; ++i)
54 {
55
56 retry:
57
58 try
59 {
60 cout << "Generating point " << i << endl;
61
62 const Geom_Number x = gsl_ran_flat(r, min_x, max_x);
63 const Geom_Number y = gsl_ran_flat(r, min_y, max_y);
64
65 cout << Point(x, y).to_string() << " triying ..." << endl;
66
67 poly.add_vertex(Point(x, y));
68
69 cout << "success" << endl;
70 }
71 catch (domain_error)
72 {
73 cout << " crosses" << endl;
74 goto retry;
75 }
76 }
77
78 cout << "closing ..." << endl;
79
80 try
81 {
82 poly.close();
83
84 cout << "Finished polygon generation" << endl;
85
87
88 return poly;
89 }
90 catch (domain_error)
91 {
92 cout << " close crosses" << endl;
93
94 goto again;
95 }
96 }
97}
98
99
100int main()
101{
102 Segment sg0(Point(232, 438), Point(1227, 2183));
103 Segment sg1(Point(162, 1838), Point(327, 883));
104 Segment sg2(Point(16, 38), Point(827, 783));
105 Segment sg3(Point(1000, 1500), Point(10, 183));
106 Segment sg4(Point(200, 300), Point(-800, 1600));
107 Segment sg5(Point(0, 1400), Point(1800, 0));
108
109 Segment s1(Point(0, 0), Point(0, 1400));
110 Segment s2(Point(0, 1400), Point(2800, 1400));
111
112 Point p1 = sg4.intersection_with(sg5);
113
114 Triangle tr(Point(-1632, 237), Point(737, 235), Point(272, 1772));
115
116 Triangle tr1(Point(0, 0), Point(600, 600), Point(800, 0));
117
118 Ellipse el(Point(-800, 600), 800, 330);
119
120 Point pt(400 + 700, 400 + 100);
121
122# ifdef nada
123 if (el.contains_to(pt))
124 cout << "El punto de prueba " << pt.to_string()
125 << " está dentro de la elipse de centro "
126 << el.get_center().to_string() << endl
127 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
128 << endl;
129 else
130 cout << "Falló prueba de inclusión del punto " << pt.to_string()
131 << " en elipse de centro "
132 << el.get_center().to_string() << endl
133 << "con a = " << el.get_hradius() << " y b = " << el.get_vradius()
134 << endl;
135
136 char c;
137
138 cin >> c;
139# endif
140
141 Eepic_Plane plane(2000, 2000);
142
143 put_in_plane(plane, pt);
144
145 put_in_plane(plane, Arrow(s1));
146 put_in_plane(plane, s2);
147
148 put_in_plane(plane, p1);
149
150 put_in_plane(plane, sg4);
151 put_in_plane(plane, sg5);
152
153 put_in_plane(plane, sg1);
154 put_in_plane(plane, sg2);
155 put_in_plane(plane, sg3);
156
157 put_in_plane(plane, tr);
158 put_in_plane(plane, tr1);
159 put_in_plane(plane, el);
160
162
163 Segment ts1, ts2;
164
165 el.compute_tangents(ts1, ts2, 3.25);
166
167 put_in_plane(plane, Arrow(ts1));
168 put_in_plane(plane, ts2);
169
170 Segment par(ts1, 100);
171
172 put_in_plane(plane, Arrow(par));
173
174 Segment seg (Point(4,0), Point(-300, 400));
176
177 put_in_plane(plane, inter);
178
179 put_in_plane(plane, inter.get_src_point());
180 put_in_plane(plane, inter.get_tgt_point());
181
182# ifdef nada
183 put_in_plane(plane,
184 Text(sg0.get_tgt_point(),
185 gnu::autosprintf("m0 = %.2f", sg0.slope())));
186 put_in_plane(plane, Arrow(sg0));
187
188 put_in_plane(plane,
189 Text(sg1.get_tgt_point(),
190 gnu::autosprintf("m1 = %.2f", sg1.slope())));
191 put_in_plane(plane, Arrow(sg1));
192
193 put_in_plane(plane,
194 Text(sg2.get_tgt_point(),
195 gnu::autosprintf("m2 = %.2f", sg2.slope())));
196 put_in_plane(plane, Arrow(sg2));
197
198 put_in_plane(plane,
199 Text(sg3.get_tgt_point(),
200 gnu::autosprintf("m3 = %.2f", sg3.slope())));
201 put_in_plane(plane, Arrow(sg3));
202
203 put_in_plane(plane,
204 Text(sg4.get_tgt_point(),
205 gnu::autosprintf("m4 = %.2f", sg4.slope())));
206 put_in_plane(plane, Arrow(sg4));
207# endif
208 // put_in_plane(plane, seg);
209 // put_in_plane(plane, inter);
210
211 // put_in_plane(plane, Arrow(Point(20, 20), Point(400, 500)));
212
213 // put_in_plane(plane, Thick_Segment(Point(19,100), Point(582, 267)));
214
215 // put_in_plane(plane, Thick_Arrow(Point(19,100), Point(82, 267)));
216
217 // put_in_plane(plane, Dotted_Segment(Point(190, 100), Point(820, 267)));
218
219 // put_in_plane(plane, Dash_Segment(Point(200, 190), Point(267, 420)));
220
221 // put_in_plane(plane, Arrow_Dash_Segment(Point(267, 820), Point(10,190)));
222
223 // put_in_plane(plane, Arrow_Dotted_Segment(Point(67, 20), Point(100,190)));
224
225 // plane.compute_extreme_points();
226
227 Polygon poly = make_random_polygon(13, 0, 2000, 0, 1400);
228
229 // put_in_plane(plane, Spline(poly));
230
231 // put_in_plane(plane, Spline_Arrow(poly));
232
233 // put_in_plane(plane, Polygon_With_Arrows(poly));
234
235 put_in_plane(plane, poly);
236
237 // put_in_plane(plane, Shade_Polygon(poly));
238
239 // put_in_plane(plane, Regular_Polygon(Point(0, 0), 400, 12, PI/3));
240
241 // put_in_plane(plane, Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
242
243 // put_in_plane(plane, Dotted_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
244
245 // put_in_plane(plane, Dash_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
246
247 // put_in_plane(plane,
248 // Dotted_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
249
250 // put_in_plane(plane,
251 // Dash_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
252
253 // put_in_plane(plane, Shade_Regular_Polygon(Point(0, 0), 400, 12, PI/3));
254
255 // put_in_plane(plane,
256 // Shade_Regular_Polygon_With_Points(Point(0, 0), 400, 12, PI/3));
257
258 // put_in_plane(plane,
259 // Shade_Regular_Polygon_With_Arrows(Point(0, 0), 400, 12, PI/3));
260
261 // put_in_plane(plane, Eepic_Spline(Point(-100, -200), 400, 7, PI/3));
262
263 Regular_Polygon reg_poly(Point(200, 790), 300, 5);
264
265 // put_in_plane(plane, reg_poly);
266
267 // Polygon p(reg_poly);
268
269 // put_in_plane(plane, Polygon(p));
270
271 Segment linea1(Point(100, 100), Point(400, 200));
272
274
275 put_in_plane(plane, Arrow(linea1));
276
278
279 put_in_plane(plane, perp1.get_src_point());
280
281 put_in_plane(plane, perp1.get_tgt_point());
282
283 Segment linea2(Point(100, 100), Point(400, -200));
284
286
287 put_in_plane(plane, Arrow(linea2));
288
290
291 put_in_plane(plane, perp2.get_src_point());
292
293 put_in_plane(plane, perp2.get_tgt_point());
294
295 Segment linea3(Point(100, 100), Point(-400, -200));
296
298
299 put_in_plane(plane, Arrow(linea3));
300
302
303 put_in_plane(plane, perp3.get_src_point());
304
305 put_in_plane(plane, perp3.get_tgt_point());
306
307 Segment linea4(Point(100, 100), Point(-400, 200));
308
310
311 put_in_plane(plane, Arrow(linea4));
312
314
315 put_in_plane(plane, perp4.get_src_point());
316
317 put_in_plane(plane, perp4.get_tgt_point());
318
319 // put_in_plane(plane, Spline(Regular_Polygon(Point(-300, -300), 300, 4)));
320
321 // put_in_plane(plane, Spline_Arrow(Regular_Polygon(Point(-300, 300), 300, 4)));
322
324
325 put_in_plane(plane, Ellipse(Point(-100, -100), 200, 100));
326
327 // put_in_plane(plane, Shade_Ellipse(el));
328
329 ofstream output1("test-1.eepic", ios::trunc);
330
331 plane.put_cartesian_axis();
332
333 plane.draw(output1);
334
335 ofstream output2("test-2.eepic", ios::trunc);
336
337 plane.zoom(0.25);
338 plane.draw(output2);
339
340
341}
An axis-aligned ellipse.
Definition point.H:2006
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
std::string to_string() const
Returns a string representation of the point as "(x,y)".
Definition point.H:651
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:246
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:677
void close()
Close the polygon.
Definition polygon.H:840
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:1132
Represents a line segment between two points.
Definition point.H:827
Point intersection_with(const Segment &s) const
Computes the intersection point of the infinite lines defined by two segments.
Definition point.H:1313
Segment mid_perpendicular(const Geom_Number &dist) const
Returns the perpendicular chord of a given length passing through the midpoint.
Definition point.H:1212
Represents a text string positioned at a 2D point.
Definition point.H:2739
A non-degenerate triangle defined by three points.
Definition point.H:1478
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:1456
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
STL namespace.
Segment-drawing variants (types).
Definition eepicgeom.H:1214
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