Skip to content

How to mirror geometries? #1002

Answered by tinko92
Jihadist asked this question in Q&A
Discussion options

You must be logged in to vote

The algorithm boost::geometry::transform with a scale-strategy with a negative value for one of the dimensions might be what you are looking for.

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

int main()
{
    using namespace boost::geometry;
    using namespace boost::geometry::strategy::transform;
    using point_2d = model::d2::point_xy<double>;
    
    point_2d p(2,5), pm;
    scale_transformer<double, 2, 2> mirror(-1, 1);
    transform(p, pm, mirror);
    std::cout << wkt(pm) << "\n"; //POINT(-2 5)

    return 0;
}

More generally, with matrix_transformer you can have arbitrary affine transformations, this example shows how they c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Jihadist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1001 on May 16, 2022 09:57.