Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) BoostGeometryExample4

 

BoostQt CreatorLubuntu

 

Boost.Geometry example 4: CalcPlane: determine the plane passing through three point is a Boost.Geometry example.

 

CalcCrossProduct and CalcPlane are maintained in CppGeometry. See CppGeometry for the heavily used, debugged and tested versions of CalcCrossProduct and CalcPlane.

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppBoostGeometryExample4/CppBoostGeometryExample4.pro

 

exists(../../ConsoleApplication.pri) {
  include(../../ConsoleApplication.pri)
}
!exists(../../ConsoleApplication.pri) {
  QT += core
  QT += gui
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  CONFIG   += console
  CONFIG   -= app_bundle
  TEMPLATE = app
  CONFIG(release, debug|release) {
    DEFINES += NDEBUG NTRACE_BILDERBIKKEL
  }
  QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
  unix {
    QMAKE_CXXFLAGS += -Werror
  }
}

exists(../../Libraries/Boost.pri) {
  include(../../Libraries/Boost.pri)
}
!exists(../../Libraries/Boost.pri) {
  win32 {
    INCLUDEPATH += \
      ../../Libraries/boost_1_55_0
  }
}

SOURCES += main.cpp

 

 

 

 

 

./CppBoostGeometryExample4/main.cpp

 

#include <cassert>
#include <functional>
#include <iostream>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-variable"
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/point.hpp>
#pragma GCC diagnostic pop

typedef boost::geometry::model::point<int,3,boost::geometry::cs::cartesian> Point3D;

std::function<bool(const Point3D& lhs, const Point3D& rhs)> OrderByX() noexcept
{
  return [](const Point3D& lhs, const Point3D& rhs)
  {
    using boost::geometry::get;
    if (get<0>(lhs) < get<0>(rhs)) return true;
    if (get<0>(lhs) > get<0>(rhs)) return false;
    if (get<1>(lhs) < get<1>(rhs)) return true;
    if (get<1>(lhs) > get<1>(rhs)) return false;
    return get<2>(lhs) < get<2>(rhs);
  };
}

std::function<bool(const Point3D& lhs, const Point3D& rhs)> OrderByZ() noexcept
{
  return [](const Point3D& lhs, const Point3D& rhs)
  {
    using boost::geometry::get;
    if (get<2>(lhs) < get<2>(rhs)) return true;
    if (get<2>(lhs) > get<2>(rhs)) return false;
    if (get<1>(lhs) < get<1>(rhs)) return true;
    if (get<1>(lhs) > get<1>(rhs)) return false;
    return get<0>(lhs) < get<0>(rhs);
  };
}

std::ostream& operator<<(std::ostream& os, const Point3D& p)
{
  using boost::geometry::get;
  os << "("  << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << ")";
  return os;
}

int main()
{
  std::vector<Point3D> v {
    Point3D(0,0,0),
    Point3D(0,0,1),
    Point3D(0,1,0),
    Point3D(0,1,1),
    Point3D(1,0,0),
    Point3D(1,0,1),
    Point3D(1,1,0),
    Point3D(1,1,1)
  };
  std::random_shuffle(v.begin(),v.end());
  std::cout << "Random" << '\n';
  for (const auto p:v) { std::cout << p << '\n'; }
  std::sort(v.begin(),v.end(),OrderByX());

  std::cout << "Sorted by X-Y-Z" << '\n';
  for (const auto p:v) { std::cout << p << '\n'; }
  std::sort(v.begin(),v.end(),OrderByZ());

  std::cout << "Sorted by Z-Y-X" << '\n';
  for (const auto p:v) { std::cout << p << '\n'; }
}

/* Screen output

Random
(1,0,0)
(0,0,1)
(1,1,0)
(0,1,0)
(0,0,0)
(1,0,1)
(1,1,1)
(0,1,1)
Sorted by X-Y-Z
(0,0,0)
(0,0,1)
(0,1,0)
(0,1,1)
(1,0,0)
(1,0,1)
(1,1,0)
(1,1,1)
Sorted by Z-Y-X
(0,0,0)
(1,0,0)
(0,1,0)
(1,1,0)
(0,0,1)
(1,0,1)
(0,1,1)
(1,1,1)
Press <RETURN> to close this window...

*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml