Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
rotating_calipers_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
44# include <geom_algorithms.H>
45
46# include <cassert>
47# include <iostream>
48
49using namespace Aleph;
50using namespace std;
51
52static void print_banner(const char * title)
53{
54 cout << "[Aleph Geometry Example] " << title << "\n";
55 cout << "============================================================\n";
56}
57
59{
60 Polygon poly;
61 poly.add_vertex(Point(0, 0));
62 poly.add_vertex(Point(8, 0));
63 poly.add_vertex(Point(8, 3));
64 poly.add_vertex(Point(0, 3));
65 poly.close();
66 return poly;
67}
68
69int main()
70{
71 print_banner("Rotating Calipers");
72
73 const Polygon rect = build_rect_8x3();
74
75 const auto diameter = RotatingCalipersConvexPolygon::diameter(rect);
77
78 cout << "Diameter endpoints: ("
79 << diameter.first.get_x() << ", " << diameter.first.get_y() << ") <-> ("
80 << diameter.second.get_x() << ", " << diameter.second.get_y() << ")" << endl;
81 cout << "Diameter distance^2: " << diameter.distance_squared << endl;
82 cout << "Minimum width support edge: ("
83 << width.edge_first.get_x() << ", " << width.edge_first.get_y() << ") -> ("
84 << width.edge_second.get_x() << ", " << width.edge_second.get_y() << ")" << endl;
85 cout << "Antipodal vertex: (" << width.antipodal.get_x()
86 << ", " << width.antipodal.get_y() << ")" << endl;
87 cout << "Minimum width^2: " << width.width_squared << endl;
88
89 // Rectangle 8x3:
90 // - diameter^2 = 8^2 + 3^2 = 73
91 // - minimum width^2 = min(8,3)^2 = 9
92 assert(diameter.distance_squared == Geom_Number(73));
93 assert(width.width_squared == Geom_Number(9));
94
95 cout << "Validation OK for 8x3 rectangle." << endl;
96 cout << "STATUS: OK" << endl;
97 return 0;
98}
Represents a point with rectangular coordinates in a 2D plane.
Definition point.H:229
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
static DiameterResult diameter(const Polygon &poly)
Compute convex polygon diameter (farthest vertex pair).
static WidthResult minimum_width(const Polygon &poly)
Compute the minimum width of a closed convex polygon.
Computational geometry algorithms.
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 Polygon build_rect_8x3()
static void print_banner(const char *title)