CGAL 6.1.1 - Weights

Loading...
Searching...
No Matches
Weights/coordinates_one_query.cpp
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Weights/discrete_harmonic_weights.h>
// Typedefs.
using Kernel = CGAL::Simple_cartesian<double>;
using FT = typename Kernel::FT;
using Point_2 = typename Kernel::Point_2;
int main() {
// Create a polygon and a query point.
const std::vector<Point_2> polygon =
{ Point_2(0, 0), Point_2(1, 0), Point_2(1, 1), Point_2(0, 1) };
const Point_2 query(0.5, 0.5);
// Allocate memory for weights and coordinates.
std::vector<FT> weights;
weights.reserve(polygon.size());
std::vector<FT> coordinates;
coordinates.reserve(polygon.size());
// Compute barycentric weights.
CGAL::Weights::discrete_harmonic_weights_2(polygon, query, std::back_inserter(weights));
assert(weights.size() == polygon.size());
std::cout << "2D weights: ";
for (const FT weight : weights) {
std::cout << weight << " ";
}
std::cout << std::endl;
// Normalize weights in order to get barycentric coordinates.
FT sum = 0.0;
for (const FT weight : weights) {
sum += weight;
}
assert(sum != 0.0);
for (const FT weight : weights) {
coordinates.push_back(weight / sum);
}
assert(coordinates.size() == weights.size());
std::cout << "2D coordinates: ";
for (const FT coordinate : coordinates) {
std::cout << coordinate << " ";
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
Kernel::Point_2
CGAL::Weights::discrete_harmonic_weights_2
OutIterator discrete_harmonic_weights_2(const PointRange &polygon, const typename GeomTraits::Point_2 &query, OutIterator w_begin, const GeomTraits &traits)
computes 2D discrete harmonic weights for polygons.
Definition: discrete_harmonic_weights.h:366
Kernel
CGAL::Simple_cartesian