File: segment_coordinates.cpp

package info (click to toggle)
cgal 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 141,840 kB
  • sloc: cpp: 797,081; ansic: 203,398; sh: 490; python: 411; makefile: 286; javascript: 174
file content (45 lines) | stat: -rw-r--r-- 1,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Barycentric_coordinates_2/segment_coordinates_2.h>

// Typedefs.
using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;

using FT      = Kernel::FT;
using Point_2 = Kernel::Point_2;

int main() {

  const FT y = FT(2) / FT(5);

  // Construct a segment.
  const Point_2 source(FT(0), y);
  const Point_2 target(FT(2), y);

  // Construct three interior and two exterior query points.
  const std::vector<Point_2> queries = {
    Point_2(FT(2) / FT(5), y), // interior query points
    Point_2(FT(5) / FT(5), y),
    Point_2(FT(8) / FT(5), y),

    Point_2(-FT(1) / FT(5), y), // exterior query points
    Point_2(FT(11) / FT(5), y) };

  // Compute segment coordinates.
  std::vector<FT> coordinates;
  coordinates.reserve(queries.size() * 2);

  for (const auto& query : queries) {
    CGAL::Barycentric_coordinates::segment_coordinates_2(
      source, target, query, std::back_inserter(coordinates));
  }

  // Output all segment coordinates.
  std::cout << std::endl << "segment coordinates (all queries): " << std::endl << std::endl;
  for (std::size_t i = 0; i < coordinates.size(); i += 2) {
    std::cout <<
    coordinates[i + 0] << ", " <<
    coordinates[i + 1] << std::endl;
  }
  std::cout << std::endl;
  return EXIT_SUCCESS;
}