geometry/doc/quickbook/quickstart.qbk
2010-02-20 15:44:35 +00:00

64 lines
2.2 KiB
Plaintext

[/==============================================================================
Copyright (c) 1995-2009 Barend Gehrels, Geodan, Amsterdam, the Netherlands.
Copyright (c) 2008-2009 Bruno Lalande, Paris, France.
Copyright (c) 2009 Mateusz Loskot (mateusz@loskot.net)
Use, modification and distribution is subject to the Boost Software License,
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
===============================================================================/]
[section:quickstart Quick Start]
It is not possible to present all features of the whole library at a glance.
However, a few very small examples are shown below.
It should be possible to use a very small part of the library, for example
only the distance between two points.
int a[2] = {1,1};
int b[2] = {2,3};
double d = distance(a, b);
std::cout << "Distance a-b is:" << d << std::endl;
Other often used algorithms are point-in-polygon:
ring_2d poly;
double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}};
append(poly, points);
boost::tuple<double, double> p = boost::make_tuple(3.7, 2.0);
std::cout << "Point p is in polygon? " << (within(p, poly) ? "YES" : "NO") << std::endl;
or area:
std::cout << "Area: " << area(poly) << std::endl;
It is possible, by the nature of a template library, to mix the point types declared above:
double d2 = distance(a, p);
std::cout << "Distance a-p is:" << d2 << std::endl;
The pieces above generate this output:
__img_quickstart_output__
It is also possible to use non-Cartesian points. For example: points on a sphere.
When then an algorithm such as distance is used the library "inspects" that it
is handling spherical points and calculates the distance over the sphere,
instead of applying the Pythagorean theorem.
Finally an example from a totally different domain: developing window-based applications,
for example using QtWidgets. We check if two rectangles overlap and if so, move the second
one to another place:
QRect r1(100, 200, 15, 15);
QRect r2(110, 210, 20, 20);
if (overlaps(r1, r2))
{
assign(r2, 200, 300, 220, 320);
}
More examples are on the page Examples
[endsect]