1
votes

I am trying to make a simple 2d 'physics' simulation primarily involving the collision of circular objects, and in order to avoid programming my own spatial index (quad tree/r-tree/etc) I was hoping to use Boost's R-tree.

The problem is that I can't find any documentation or examples in the Boost documentation on how one creates circular shapes (or if it is even possible). There is plenty of documentation on creating arbitrary polygon objects. Is this possible using the Boost geometry library, and if so how does one go about doing it?

Edited: to clarify that I was not asking about how one finds if two circles intersect.

1
It seems to me like you have two different problems, one is to make "circles" (whatever that means in your context), and another to check for intersection. It it's really so then you should be asking two different questions.Some programmer dude
If distance between two centers is less than the sum of their radius then they intersect.101010
@Joachim Pileborg The intent of the question was to determine if objects can be created using the boost geometry library that represent circles (similarly to how one can create polygon objects) and, if so, does boost supports geometric Boolean operators for circles. (intersection, union, etc). Can you tell me if you think there is a better way to reword the question?yuriy206
@101010 I apologize for the misunderstanding, I understand the general geometric way of checking if two circles intersect, I was trying to determine if there was a way to do this using the boost library (mainly for the purpose of putting said circular objects into the boost provided r-tree.)yuriy206

1 Answers

0
votes

To make a disk in boost, one can use the buffer method (see doc for details on buffer function and strategies):

// boost namespace and types
namespace bg  = boost::geometry;
typedef bg::model::d2::point_xy<double> BPoint;
typedef bg::model::polygon<BPoint> BPolygon;
typedef bg::model::multi_polygon<BPolygon> BMultiPolygon;

// declare all buffer strategies
int points_per_circle(10);
bg::strategy::buffer::join_round join_strategy(points_per_circle);
boost::geometry::strategy::buffer::end_flat end_strategy;
bg::strategy::buffer::point_circle circle_strategy(points_per_circle);
bg::strategy::buffer::side_straight side_strategy;

// set the distance strategy
double radius = 20;
bg::strategy::buffer::distance_symmetric<double> distance_strategy(radius);

BPoint center = BPoint(0, 0);
BMultiPolygon tmp;  // buffer generates multipolygons
BPolygon disk;

// make disk centered on `center` and of correct `radius`
bg::buffer(start, tmp, distance_strategy, side_strategy,
           join_strategy, end_strategy, circle_strategy);

// convert the MultiPolygon output to a simple polygon
disk = BPolygon(tmp[0]);