Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
geom_example.C
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
132#include <iostream>
133#include <iomanip>
134#include <cmath>
135#include <chrono>
136#include <cstring>
137
138#include <geom_algorithms.H>
139#include <tpl_dynArray.H>
140
141# include <cstdlib>
142using namespace std;
143# include <cstdlib>
144using namespace Aleph;
145
146// ============================================================================
147// Helper functions
148// ============================================================================
149
150void print_header(const string& title)
151{
152 cout << "\n";
153 cout << "+" << string(70, '-') << "+" << endl;
154 cout << "| " << left << setw(68) << title << " |" << endl;
155 cout << "+" << string(70, '-') << "+" << endl;
156}
157
158void print_subheader(const string& subtitle)
159{
160 cout << "\n " << subtitle << endl;
161 cout << " " << string(subtitle.length(), '-') << endl;
162}
163
167inline double to_double(const Geom_Number& n)
168{
169 return n.get_d();
170}
171
175void print_point(const Point& p, const string& label = "")
176{
177 cout << " ";
178 if (!label.empty()) cout << label << ": ";
179 cout << "(" << fixed << setprecision(2) << to_double(p.get_x())
180 << ", " << to_double(p.get_y()) << ")" << endl;
181}
182
186void print_polygon(const Polygon& poly, const string& name)
187{
188 cout << "\n " << name << " (" << poly.size() << " vertices):" << endl;
189 int i = 0;
190 for (Polygon::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
191 {
192 const Vertex& v = it.get_current_vertex();
193 cout << " V" << i++ << ": (" << fixed << setprecision(2)
194 << to_double(v.get_x()) << ", " << to_double(v.get_y()) << ")" << endl;
195 }
196}
197
201void print_triangle(const Triangle& t, int index)
202{
203 cout << " T" << index << ": ";
204 const Point& a = t.get_p1();
205 const Point& b = t.get_p2();
206 const Point& c = t.get_p3();
207 cout << "(" << fixed << setprecision(1)
208 << to_double(a.get_x()) << "," << to_double(a.get_y()) << ") - "
209 << "(" << to_double(b.get_x()) << "," << to_double(b.get_y()) << ") - "
210 << "(" << to_double(c.get_x()) << "," << to_double(c.get_y()) << ")" << endl;
211}
212
216double triangle_area(const Triangle& t)
217{
218 const Point& a = t.get_p1();
219 const Point& b = t.get_p2();
220 const Point& c = t.get_p3();
221
222 double ax = to_double(b.get_x()) - to_double(a.get_x());
223 double ay = to_double(b.get_y()) - to_double(a.get_y());
224 double bx = to_double(c.get_x()) - to_double(a.get_x());
225 double by = to_double(c.get_y()) - to_double(a.get_y());
226
227 return 0.5 * abs(ax * by - ay * bx);
228}
229
230// ============================================================================
231// Example 1: Basic Polygon Triangulation
232// ============================================================================
233
235{
236 print_header("Example 1: Polygon Triangulation - Basic Shapes");
237
238 // Create a simple square (represents Plaza de Bolivar, Bogota)
239 print_subheader("Square (Plaza de Bolivar)");
240
241 Polygon square;
242 square.add_vertex(Point(0, 0));
243 square.add_vertex(Point(100, 0));
244 square.add_vertex(Point(100, 100));
245 square.add_vertex(Point(0, 100));
246 square.close();
247
248 print_polygon(square, "Original polygon");
249
251 DynList<Triangle> triangles = triangulator(square);
252
253 cout << "\n Triangulation result:" << endl;
254 int i = 0;
255 double total_area = 0;
256 for (auto it = triangles.get_it(); it.has_curr(); it.next_ne())
257 {
258 const Triangle& t = it.get_curr();
259 print_triangle(t, i++);
261 }
262
263 cout << "\n Total triangles: " << triangles.size() << endl;
264 cout << " Total area: " << fixed << setprecision(2) << total_area
265 << " square units" << endl;
266 cout << " Expected area: 10000.00 square units" << endl;
267
268 // Create a pentagon (star shape simplified)
269 print_subheader("Pentagon");
270
271 Polygon pentagon;
272 double radius = 50;
273 for (int j = 0; j < 5; ++j)
274 {
275 double angle = 2 * M_PI * j / 5 - M_PI / 2;
276 pentagon.add_vertex(Point(radius * cos(angle), radius * sin(angle)));
277 }
278 pentagon.close();
279
280 print_polygon(pentagon, "Pentagon");
281
283
284 cout << "\n Triangulation result:" << endl;
285 i = 0;
286 total_area = 0;
287 for (auto it = pent_triangles.get_it(); it.has_curr(); it.next_ne())
288 {
289 const Triangle& t = it.get_curr();
290 print_triangle(t, i++);
292 }
293
294 cout << "\n Total triangles: " << pent_triangles.size() << endl;
295 cout << " Total area: " << fixed << setprecision(2) << total_area
296 << " square units" << endl;
297}
298
299// ============================================================================
300// Example 2: Triangulation of Complex Polygon
301// ============================================================================
302
304{
305 print_header("Example 2: Complex Polygon Triangulation");
306
307 // Create an L-shaped polygon (like a building footprint)
308 print_subheader("L-shaped polygon (Building footprint)");
309
311 l_shape.add_vertex(Point(0, 0));
312 l_shape.add_vertex(Point(60, 0));
313 l_shape.add_vertex(Point(60, 40));
314 l_shape.add_vertex(Point(40, 40));
315 l_shape.add_vertex(Point(40, 80));
316 l_shape.add_vertex(Point(0, 80));
317 l_shape.close();
318
319 print_polygon(l_shape, "L-shaped polygon");
320
323
324 cout << "\n Triangulation result:" << endl;
325 int i = 0;
326 double total_area = 0;
327 for (auto it = triangles.get_it(); it.has_curr(); it.next_ne())
328 {
329 const Triangle& t = it.get_curr();
330 print_triangle(t, i++);
332 }
333
334 cout << "\n Total triangles: " << triangles.size() << endl;
335 cout << " Total area: " << fixed << setprecision(2) << total_area
336 << " square units" << endl;
337
338 // Verify: L-shape area = 60*40 + 40*40 = 2400 + 1600 = 4000
339 cout << " Expected area: 4000.00 square units (60x40 + 40x40)" << endl;
340}
341
342// ============================================================================
343// Example 3: Convex Hull - Colombian Cities
344// ============================================================================
345
347{
348 print_header("Example 3: Convex Hull - Colombian Cities");
349
350 // Approximate coordinates of Colombian cities (scaled for visibility)
351 // Using a simplified coordinate system where (0,0) is near Leticia
352
354
355 // Major Colombian cities (approximate positions)
356 struct CityCoord { const char* name; double x; double y; };
358 city_data.append({"Bogota", 74, 44});
359 city_data.append({"Medellin", 75, 61});
360 city_data.append({"Cali", 76, 34});
361 city_data.append({"Barranquilla", 74, 109});
362 city_data.append({"Cartagena", 75, 104});
363 city_data.append({"Cucuta", 72, 77});
364 city_data.append({"Bucaramanga", 73, 71});
365 city_data.append({"Pereira", 75, 47});
366 city_data.append({"Santa Marta", 74, 111});
367 city_data.append({"Ibague", 75, 44});
368 city_data.append({"Pasto", 77, 12});
369 city_data.append({"Manizales", 75, 51});
370 city_data.append({"Villavicencio", 73, 41});
371 city_data.append({"Armenia", 75, 44});
372 city_data.append({"Leticia", 70, 0}); // Amazon
373 city_data.append({"Riohacha", 72, 116}); // La Guajira
374
375 cout << "\n Colombian cities included:" << endl;
376 for (size_t i = 0; i < city_data.size(); ++i)
377 {
378 const auto& c = city_data(i);
379 cout << " " << left << setw(15) << c.name
380 << "(" << c.x << ", " << c.y << ")" << endl;
381 cities.append(Point(c.x, c.y));
382 }
383
384 // Make copies for each algorithm
386 for (auto it = cities.get_it(); it.has_curr(); it.next_ne())
387 {
388 cities_bf.append(it.get_curr());
389 cities_gw.append(it.get_curr());
390 cities_qh.append(it.get_curr());
391 }
392
393 // Test each convex hull algorithm
394 print_subheader("Brute Force Convex Hull O(n^3)");
395
397 auto start = chrono::high_resolution_clock::now();
399 auto end = chrono::high_resolution_clock::now();
400 auto bf_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
401
402 cout << " Hull vertices: " << hull_bf.size() << endl;
403 cout << " Time: " << bf_time << " microseconds" << endl;
404
405 print_subheader("Gift Wrapping Convex Hull O(nh)");
406
408 start = chrono::high_resolution_clock::now();
410 end = chrono::high_resolution_clock::now();
411 auto gw_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
412
413 cout << " Hull vertices: " << hull_gw.size() << endl;
414 cout << " Time: " << gw_time << " microseconds" << endl;
415
416 print_subheader("QuickHull O(n log n) average");
417
419 start = chrono::high_resolution_clock::now();
421 end = chrono::high_resolution_clock::now();
422 auto qh_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
423
424 cout << " Hull vertices: " << hull_qh.size() << endl;
425 cout << " Time: " << qh_time << " microseconds" << endl;
426
427 // Show which cities are on the border
428 print_subheader("Cities on the convex hull (border of Colombia)");
429
430 cout << " The convex hull represents the outermost cities:" << endl;
431 for (Polygon::Vertex_Iterator it(hull_qh); it.has_curr(); it.next_ne())
432 {
433 const Vertex& v = it.get_current_vertex();
434 // Find the city name
435 for (size_t i = 0; i < city_data.size(); ++i)
436 {
437 const auto& c = city_data(i);
438 if (abs(c.x - to_double(v.get_x())) < 0.5 &&
439 abs(c.y - to_double(v.get_y())) < 0.5)
440 {
441 cout << " - " << c.name << endl;
442 break;
443 }
444 }
445 }
446}
447
448// ============================================================================
449// Example 4: Convex Hull - Random Points Performance
450// ============================================================================
451
453{
454 print_header("Example 4: Convex Hull Algorithm Performance");
455
456 cout << "\n Comparing algorithms on random point sets:" << endl;
457 cout << " " << string(60, '-') << endl;
458
459 DynArray<int> sizes;
460 sizes.append(10);
461 sizes.append(50);
462 sizes.append(100);
463 sizes.append(200);
464
465 cout << "\n " << setw(8) << "Points"
466 << setw(15) << "Brute Force"
467 << setw(15) << "Gift Wrap"
468 << setw(15) << "QuickHull"
469 << setw(10) << "Hull Size" << endl;
470 cout << " " << string(60, '-') << endl;
471
472 for (size_t s = 0; s < sizes.size(); ++s)
473 {
474 int n = sizes(s);
475
476 // Generate random points
478 srand(42); // Fixed seed for reproducibility
479
480 for (int i = 0; i < n; ++i)
481 {
482 double x = (rand() % 1000) / 10.0;
483 double y = (rand() % 1000) / 10.0;
484 points_bf.append(Point(x, y));
485 points_gw.append(Point(x, y));
486 points_qh.append(Point(x, y));
487 }
488
489 // Time each algorithm
493
494 auto start = chrono::high_resolution_clock::now();
496 auto end = chrono::high_resolution_clock::now();
497 auto bf_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
498
499 start = chrono::high_resolution_clock::now();
501 end = chrono::high_resolution_clock::now();
502 auto gw_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
503
504 start = chrono::high_resolution_clock::now();
506 end = chrono::high_resolution_clock::now();
507 auto qh_time = chrono::duration_cast<chrono::microseconds>(end - start).count();
508
509 cout << " " << setw(8) << n
510 << setw(12) << bf_time << " us"
511 << setw(12) << gw_time << " us"
512 << setw(12) << qh_time << " us"
513 << setw(10) << hull_qh.size() << endl;
514 }
515
516 cout << "\n Note: Times in microseconds (us)" << endl;
517 cout << " Brute Force grows as O(n^3)" << endl;
518 cout << " Gift Wrapping grows as O(nh) where h = hull size" << endl;
519 cout << " QuickHull grows as O(n log n) on average" << endl;
520}
521
522// ============================================================================
523// Example 5: Geometric Primitives Demo
524// ============================================================================
525
527{
528 print_header("Example 5: Geometric Primitives");
529
530 print_subheader("Points and Segments");
531
532 // Create some points
533 Point bogota(74, 44);
534 Point medellin(75, 61);
535 Point cali(76, 34);
536
537 cout << " Three major Colombian cities:" << endl;
538 print_point(bogota, "Bogota");
539 print_point(medellin, "Medellin");
540 print_point(cali, "Cali");
541
542 // Create segments (routes)
545
546 cout << "\n Route lengths (approximate):" << endl;
547 cout << " Bogota-Medellin: " << fixed << setprecision(2)
548 << to_double(bogota_medellin.length()) << " units" << endl;
549 cout << " Bogota-Cali: " << to_double(bogota_cali.length())
550 << " units" << endl;
551
552 print_subheader("Point Position Tests");
553
554 Point test_point(73, 50);
555 cout << " Test point: (73, 50)" << endl;
556 cout << " Relative to line Bogota-Medellin:" << endl;
557
558 if (test_point.is_left_of(bogota, medellin))
559 cout << " Point is to the LEFT" << endl;
560 else if (test_point.is_to_right_from(bogota, medellin)) // not deprecated
561 cout << " Point is to the RIGHT" << endl;
562 else
563 cout << " Point is ON the line" << endl;
564
565 print_subheader("Triangle Operations");
566
567 Triangle triangle(bogota, medellin, cali);
568
569 cout << " Triangle formed by Bogota, Medellin, Cali:" << endl;
570 cout << " Area: " << fixed << setprecision(2)
571 << triangle_area(triangle) << " square units" << endl;
572
573 // Check points inside/outside using contains_to
574 Point inside(75, 45); // Somewhere in the middle
575 Point outside(80, 80); // Outside
576
577 cout << "\n Point containment:" << endl;
578 cout << " Point (75, 45): ";
579 if (triangle.contains(inside))
580 cout << "INSIDE the triangle" << endl;
581 else
582 cout << "OUTSIDE the triangle" << endl;
583
584 cout << " Point (80, 80): ";
585 if (triangle.contains(outside))
586 cout << "INSIDE the triangle" << endl;
587 else
588 cout << "OUTSIDE the triangle" << endl;
589}
590
591// ============================================================================
592// Example 6: Practical Application - Coverage Area
593// ============================================================================
594
596{
597 print_header("Example 6: Coverage Area Calculation");
598
599 cout << "\n Scenario: Calculate coverage area of cell towers" << endl;
600 cout << " " << string(50, '-') << endl;
601
602 // Cell tower locations (representing a region in Colombia)
604 towers.append(Point(0, 0));
605 towers.append(Point(30, 10));
606 towers.append(Point(50, 0));
607 towers.append(Point(55, 25));
608 towers.append(Point(45, 50));
609 towers.append(Point(20, 55));
610 towers.append(Point(5, 40));
611 towers.append(Point(25, 30)); // Interior tower
612 towers.append(Point(35, 25)); // Interior tower
613
614 cout << "\n Tower locations:" << endl;
615 int tower_num = 1;
616 for (auto it = towers.get_it(); it.has_curr(); it.next_ne())
617 {
618 const Point& p = it.get_curr();
619 cout << " Tower " << tower_num++ << ": ("
620 << to_double(p.get_x()) << ", "
621 << to_double(p.get_y()) << ")" << endl;
622 }
623
624 // Calculate convex hull (coverage boundary)
627
628 cout << "\n Coverage boundary (convex hull):" << endl;
629 cout << " Boundary towers: " << coverage.size() << endl;
630 cout << " Interior towers: " << (9 - coverage.size()) << endl;
631
632 // Calculate coverage area using triangulation
633 Polygon coverage_copy = coverage; // triangulation consumes the polygon
636
637 double total_area = 0;
638 for (auto it = triangles.get_it(); it.has_curr(); it.next_ne())
639 total_area += triangle_area(it.get_curr());
640
641 cout << "\n Coverage statistics:" << endl;
642 cout << " Total coverage area: " << fixed << setprecision(2)
643 << total_area << " square km" << endl;
644 cout << " Triangles in mesh: " << triangles.size() << endl;
645
646 // Perimeter calculation
647 double perimeter = 0;
648 for (Polygon::Segment_Iterator it(coverage); it.has_curr(); it.next_ne())
649 {
650 const Segment& seg = it.get_current_segment();
651 perimeter += to_double(seg.length());
652 }
653
654 cout << " Perimeter: " << perimeter << " km" << endl;
655 cout << " Compactness ratio: " << (4 * M_PI * total_area) / (perimeter * perimeter)
656 << " (1.0 = circle)" << endl;
657}
658
659// ============================================================================
660// Example 7: Advanced Geometry Algorithms
661// ============================================================================
662
664{
665 print_header("Example 7: Advanced Geometry (Delaunay/Voronoi/PIP/HPI)");
666
667 print_subheader("Delaunay + Voronoi");
668 DynList<Point> sites;
669 sites.append(Point(0, 0));
670 sites.append(Point(6, 0));
671 sites.append(Point(8, 4));
672 sites.append(Point(5, 8));
673 sites.append(Point(1, 7));
674 sites.append(Point(3, 3));
675 sites.append(Point(5, 4));
676
678 const auto dt = delaunay(sites);
679 cout << " Delaunay: sites=" << dt.sites.size()
680 << " triangles=" << dt.triangles.size() << endl;
681
683 const auto vor = voronoi(dt);
684 cout << " Voronoi: vertices=" << vor.vertices.size()
685 << " edges=" << vor.edges.size() << endl;
686
688 clip.add_vertex(Point(-2, -2));
689 clip.add_vertex(Point(10, -2));
690 clip.add_vertex(Point(10, 10));
691 clip.add_vertex(Point(-2, 10));
692 clip.close();
694 cout << " Voronoi clipped cells=" << clipped.size() << endl;
695
696 print_subheader("Point-in-Polygon (Winding Number)");
698 concave.add_vertex(Point(0, 0));
699 concave.add_vertex(Point(8, 0));
700 concave.add_vertex(Point(8, 3));
701 concave.add_vertex(Point(5, 3));
702 concave.add_vertex(Point(5, 6));
703 concave.add_vertex(Point(8, 6));
704 concave.add_vertex(Point(8, 9));
705 concave.add_vertex(Point(0, 9));
706 concave.close();
707
708 const Point q_inside(1, 1);
709 const Point q_outside(6, 4); // inside notch => outside polygon
710 cout << " q_inside -> "
711 << (PointInPolygonWinding::contains(concave, q_inside) ? "inside/boundary" : "outside")
712 << endl;
713 cout << " q_outside -> "
714 << (PointInPolygonWinding::contains(concave, q_outside) ? "inside/boundary" : "outside")
715 << endl;
716
717 print_subheader("Half-Plane Intersection");
720 hps.append(HP(Point(0, 1), Point(0, 0))); // x >= 0
721 hps.append(HP(Point(0, 0), Point(1, 0))); // y >= 0
722 hps.append(HP(Point(4, 0), Point(4, 1))); // x <= 4
723 hps.append(HP(Point(1, 4), Point(0, 4))); // y <= 4
724 hps.append(HP(Point(6, 0), Point(0, 6))); // x + y <= 6
725
727 Polygon feasible = hpi(hps);
728 cout << " Feasible polygon vertices: " << feasible.size() << endl;
729}
730
731// ============================================================================
732// Main
733// ============================================================================
734
735static void usage(const char* prog)
736{
737 cout << "Usage: " << prog
738 << " [-s <triangulation|convexhull|advanced|all>] [--help]\n";
739 cout << "\nIf no selector is given, all demos are executed.\n";
740}
741
742int main(int argc, char* argv[])
743{
744 string section = "all";
745 for (int i = 1; i < argc; ++i)
746 {
747 const string arg = argv[i];
748 if (arg == "--help" || arg == "-h")
749 {
750 usage(argv[0]);
751 return 0;
752 }
753 if (arg == "-s")
754 {
755 if (i + 1 >= argc)
756 {
757 usage(argv[0]);
758 return 1;
759 }
760 section = argv[++i];
761 continue;
762 }
763
764 cout << "Unknown argument: " << arg << "\n";
765 usage(argv[0]);
766 return 1;
767 }
768
769 cout << "\n";
770 cout << "========================================================================" << endl;
771 cout << " ALEPH-W COMPUTATIONAL GEOMETRY EXAMPLE" << endl;
772 cout << " Core + Advanced Geometry Algorithms" << endl;
773 cout << "========================================================================" << endl;
774
775 if (section == "all" || section == "triangulation")
776 {
779 }
780
781 if (section == "all" || section == "convexhull")
782 {
785 }
786
787 if (section == "all")
788 {
791 }
792
793 if (section == "all" || section == "advanced")
795
796 if (!(section == "all" || section == "triangulation" ||
797 section == "convexhull" || section == "advanced"))
798 {
799 cout << "Unknown section: " << section << "\n";
800 usage(argv[0]);
801 return 1;
802 }
803
804 cout << "\n";
805 cout << "========================================================================" << endl;
806 cout << " Example completed successfully!" << endl;
807 cout << "========================================================================" << endl;
808 cout << endl;
809
810 return 0;
811}
Simple dynamic array with automatic resizing and functional operations.
Definition tpl_array.H:139
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:245
Brute force convex hull algorithm.
Polygon triangulation using the ear-cutting algorithm.
Exact Delaunay triangulation using the Bowyer-Watson incremental algorithm.
size_t size() const noexcept
Return the current dimension of array.
T & append()
Allocate a new entry to the end of array.
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
Gift wrapping (Jarvis march) convex hull algorithm.
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1065
Exact bounded intersection of half-planes.
static bool contains(const Polygon &poly, const Point &p)
Return true if the point is inside or on the boundary.
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
Definition point.H:457
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Definition point.H:466
Iterator over the edges (segments) of a polygon.
Definition polygon.H:520
bool has_curr() const
Check if there is a current segment.
Definition polygon.H:537
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
const size_t & size() const
Get the number of vertices.
Definition polygon.H:477
QuickHull convex hull algorithm.
Represents a line segment between two points.
Definition point.H:827
Geom_Number length() const
Returns the Euclidean length of the segment.
Definition point.H:1056
A non-degenerate triangle defined by three points.
Definition point.H:1478
const Point & get_p3() const
Gets the third vertex.
Definition point.H:1591
const Point & get_p2() const
Gets the second vertex.
Definition point.H:1589
bool contains(const Point &p) const
Checks if a point lies strictly inside this triangle.
Definition point.H:1706
const Point & get_p1() const
Gets the first vertex.
Definition point.H:1587
A vertex in a polygon's doubly linked vertex list.
Definition polygon.H:119
Voronoi diagram derived as the dual of a Delaunay triangulation.
static Array< ClippedCell > clipped_cells_indexed(const Array< Point > &sites, const Polygon &clip)
Clip Voronoi cells and return explicit site-indexed records.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Definition ah-dry.H:222
Computational geometry algorithms.
void print_polygon(const Polygon &poly, const string &name)
Print a polygon's vertices.
void demo_convex_hull_performance()
void demo_triangulation_complex()
void demo_coverage_area()
void print_point(const Point &p, const string &label="")
Print a point with optional label.
void demo_advanced_algorithms()
void demo_triangulation_basic()
void print_triangle(const Triangle &t, int index)
Print a triangle.
void print_subheader(const string &subtitle)
void demo_convex_hull_cities()
double triangle_area(const Triangle &t)
Calculate area of a triangle using cross product.
double to_double(const Geom_Number &n)
Convert Geom_Number to double.
void demo_geometric_primitives()
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_cos_function > > cos(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4069
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_sin_function > > sin(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4070
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_abs_function > > abs(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4051
static mpfr_t y
Definition mpfr_mul_d.c:3
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
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.
static void section(const string &title)
void print_header()
Iterator over the vertices of a polygon.
Definition polygon.H:489
void usage()
Lazy and scalable dynamic array implementation.