Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext
transform (with strategy)

Transforms from one geometry to another geometry using the specified strategy.

Synopsis

template<typename Geometry1, typename Geometry2, typename Strategy>
bool transform(Geometry1 const & geometry1, Geometry2 & geometry2, Strategy const & strategy)

Parameters

Type

Concept

Name

Description

Geometry1 const &

Any type fulfilling a Geometry Concept

geometry1

A model of the specified concept

Geometry2 &

Any type fulfilling a Geometry Concept

geometry2

A model of the specified concept

Strategy const &

strategy

strategy

The strategy to be used for transformation

Returns

True if the transformation could be done

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/transform.hpp>

Complexity

Linear

Example

Shows how points can be scaled, translated or rotated

#include <iostream>
#include <boost/geometry.hpp>


int main()
{
    namespace trans = boost::geometry::strategy::transform;
    using boost::geometry::dsv;

    typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> point_type;

    point_type p1(1.0, 1.0);

    // Translate over (1.5, 1.5)
    point_type p2;
    trans::translate_transformer<double, 2, 2> translate(1.5, 1.5);
    boost::geometry::transform(p1, p2, translate);

    // Scale with factor 3.0
    point_type p3;
    trans::scale_transformer<double, 2, 2> scale(3.0);
    boost::geometry::transform(p1, p3, scale);

    // Rotate with respect to the origin (0,0) over 90 degrees (clockwise)
    point_type p4;
    trans::rotate_transformer<boost::geometry::degree, double, 2, 2> rotate(90.0);
    boost::geometry::transform(p1, p4, rotate);

    std::cout
        << "p1: " << dsv(p1) << std::endl
        << "p2: " << dsv(p2) << std::endl
        << "p3: " << dsv(p3) << std::endl
        << "p4: " << dsv(p4) << std::endl;

    return 0;
}

Output:

p1: (1, 1)
p2: (2.5, 2.5)
p3: (3, 3)
p4: (1, -1)

PrevUpHomeNext