|
|
|
|
@ -43,7 +43,7 @@ Example's point pattern.
|
|
|
|
|
\cgalExample{Barycentric_coordinates_2/Segment_coordinates_example.cpp}
|
|
|
|
|
|
|
|
|
|
\subsection tri_example Triangle Coordinates
|
|
|
|
|
In this example we show how to use the class `CGAL::Barycentric_coordinates::Triangle_coordinates_2` with the `Simple_cartesian` kernel for double type. We compute coordinates for three sets of points: interior (green), boundary (red), and exterior (blue). Note that some of the coordinate values for the exterior points are negative. We use a standard container of the type <a href="http://en.cppreference.com/w/cpp/container/vector">`std::vector`</a> and <a href="http://en.cppreference.com/w/cpp/iterator/insert_iterator">`std::insert_iterator`</a> to access and store the resulting coordinate values.
|
|
|
|
|
In this example we show how to use the class `CGAL::Barycentric_coordinates::Triangle_coordinates_2` with the `Simple_cartesian` kernel for double type. We compute coordinates for three sets of points: interior (green), boundary (red), and exterior (blue). Note that some of the coordinate values for the exterior points are negative. We use a standard container of the type <a href="https://en.cppreference.com/w/cpp/container/vector">`std::vector`</a> and <a href="https://en.cppreference.com/w/cpp/iterator/insert_iterator">`std::insert_iterator`</a> to access and store the resulting coordinate values.
|
|
|
|
|
|
|
|
|
|
\anchor tri_coord_example
|
|
|
|
|
\cgalFigureBegin{tri__example,triangle_coordinates_example.png}
|
|
|
|
|
@ -53,12 +53,12 @@ Example's point pattern.
|
|
|
|
|
\cgalExample{Barycentric_coordinates_2/Triangle_coordinates_example.cpp}
|
|
|
|
|
|
|
|
|
|
\subsection wp_example Wachspress Coordinates
|
|
|
|
|
In the following example we create 1000 random points, then we take the convex hull of this set of points as our polygon, and compute Wachspress coordinates at all the defined points. We use the `Simple_cartesian` kernel with double type as a traits class and store obtained coordinate values in a container of the type <a href="http://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>. The output iterator is <a href="http://en.cppreference.com/w/cpp/iterator/back_insert_iterator">`std::back_insert_iterator`</a>.
|
|
|
|
|
In the following example we create 1000 random points, then we take the convex hull of this set of points as our polygon, and compute Wachspress coordinates at all the defined points. We use the `Simple_cartesian` kernel with double type as a traits class and store obtained coordinate values in a container of the type <a href="https://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>. The output iterator is <a href="https://en.cppreference.com/w/cpp/iterator/back_insert_iterator">`std::back_insert_iterator`</a>.
|
|
|
|
|
|
|
|
|
|
\cgalExample{Barycentric_coordinates_2/Wachspress_coordinates_example.cpp}
|
|
|
|
|
|
|
|
|
|
\subsection dh_example Discrete Harmonic Coordinates
|
|
|
|
|
In this example we compute discrete harmonic coordinates for a set of green (interior), red (boundary), and blue (exterior) points with respect to a unit square. We also show how to specify the location of a query point using additional function parameters. The used kernel is exact, and we use an output container of the type <a href="http://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>. Since all the points are symmetric, it is easy to debug the correctness of the obtained coordinate values. The output iterator is <a href="http://en.cppreference.com/w/cpp/iterator/back_insert_iterator">`std::back_insert_iterator`</a>.
|
|
|
|
|
In this example we compute discrete harmonic coordinates for a set of green (interior), red (boundary), and blue (exterior) points with respect to a unit square. We also show how to specify the location of a query point using additional function parameters. The used kernel is exact, and we use an output container of the type <a href="https://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>. Since all the points are symmetric, it is easy to debug the correctness of the obtained coordinate values. The output iterator is <a href="https://en.cppreference.com/w/cpp/iterator/back_insert_iterator">`std::back_insert_iterator`</a>.
|
|
|
|
|
|
|
|
|
|
\anchor dh_coord_example
|
|
|
|
|
\cgalFigureBegin{dh__example,discrete_harmonic_coordinates_example.png}
|
|
|
|
|
@ -68,7 +68,7 @@ Example's point pattern.
|
|
|
|
|
\cgalExample{Barycentric_coordinates_2/Discrete_harmonic_coordinates_example.cpp}
|
|
|
|
|
|
|
|
|
|
\subsection mv_example Mean Value Coordinates
|
|
|
|
|
This is an example that shows how to compute mean value coordinates for a set of green points in a star-shaped polygon. We note that this type of coordinates is well-defined for such a concave polygon while Wachspress and discrete harmonic coordinates are not. However, it may give negative coordinate values for points outside <a href="https://en.wikipedia.org/wiki/Star-shaped_polygon">the polygon's kernel</a> (shown in red). We use an inexact data type, an output container of the type <a href="http://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>, and an output iterator of the type <a href="http://en.cppreference.com/w/cpp/iterator/back_insert_iterator">std::back_insert_iterator</a> to compute, access, and store the resulting coordinate values. We also show how to choose different algorithms to compute generalized barycentric coordinates (one is more precise while the other is faster).
|
|
|
|
|
This is an example that shows how to compute mean value coordinates for a set of green points in a star-shaped polygon. We note that this type of coordinates is well-defined for such a concave polygon while Wachspress and discrete harmonic coordinates are not. However, it may give negative coordinate values for points outside <a href="https://en.wikipedia.org/wiki/Star-shaped_polygon">the polygon's kernel</a> (shown in red). We use an inexact data type, an output container of the type <a href="https://en.cppreference.com/w/cpp/container/vector">`std::vector`</a>, and an output iterator of the type <a href="https://en.cppreference.com/w/cpp/iterator/back_insert_iterator">std::back_insert_iterator</a> to compute, access, and store the resulting coordinate values. We also show how to choose different algorithms to compute generalized barycentric coordinates (one is more precise while the other is faster).
|
|
|
|
|
|
|
|
|
|
\anchor mv_coord_example
|
|
|
|
|
\cgalFigureBegin{mv__example,mean_value_coordinates_example.png}
|
|
|
|
|
@ -193,7 +193,7 @@ After the normalization of these weights as before
|
|
|
|
|
|
|
|
|
|
<center>\f$b_i = \frac{w_i}{W^{mv}}\qquad\f$ with \f$\qquad W^{mv} = \sum_{j=1}^n w_j\f$</center>
|
|
|
|
|
|
|
|
|
|
we obtain the precise \f$O(n^2)\f$ algorithm. The fast O(n) algorithm computes the weights \f$w_i\f$ using the pseudocode from <a href="http://www.inf.usi.ch/hormann/nsfworkshop/presentations/Hormann.pdf">here</a>. These weights
|
|
|
|
|
we obtain the precise \f$O(n^2)\f$ algorithm. The fast O(n) algorithm computes the weights \f$w_i\f$ using the pseudocode from <a href="https://www.inf.usi.ch/hormann/nsfworkshop/presentations/Hormann.pdf">here</a>. These weights
|
|
|
|
|
|
|
|
|
|
<center>\f$w_i = \frac{t_{i-1} + t_i}{r_i}\qquad\f$ with \f$\qquad t_i = \frac{\text{det}(d_i, d_{i+1})}{r_ir_{i+1} + d_id_{i+1}}\f$</center>
|
|
|
|
|
|
|
|
|
|
@ -231,7 +231,7 @@ The package is implemented in a way that later, if needed, other two-dimensional
|
|
|
|
|
|
|
|
|
|
\section gbc_theory Theory of 2D Generalized Barycentric Coordinates
|
|
|
|
|
|
|
|
|
|
In 1827, the German mathematician and theoretical astronomer <a href="http://en.wikipedia.org/wiki/August_Ferdinand_Möbius">August Ferdinand Möbius</a> (1790--1868) proposed a method \cite cgal:bc:m-dbc-27 to find coordinates of a point in the plane with respect to the vertices of a triangle. These coordinates are called <a href="http://mathworld.wolfram.com/BarycentricCoordinates.html">triangle barycentric coordinates</a> (sometimes <a href="http://en.wikipedia.org/wiki/Barycentric_coordinate_system">area coordinates</a>), and they are widely used in a variety of applications. Some of these applications are linear interpolation over a triangle and a triangle inclusion test. The first one is used for so-called <a href="http://en.wikipedia.org/wiki/Shading">shading</a>, and the second one arises in the <a href="http://en.wikipedia.org/wiki/Rasterization">rasterization</a> step when an image in vector graphics format needs to be converted into a raster image.
|
|
|
|
|
In 1827, the German mathematician and theoretical astronomer <a href="https://en.wikipedia.org/wiki/August_Ferdinand_Möbius">August Ferdinand Möbius</a> (1790--1868) proposed a method \cite cgal:bc:m-dbc-27 to find coordinates of a point in the plane with respect to the vertices of a triangle. These coordinates are called <a href="http://mathworld.wolfram.com/BarycentricCoordinates.html">triangle barycentric coordinates</a> (sometimes <a href="https://en.wikipedia.org/wiki/Barycentric_coordinate_system">area coordinates</a>), and they are widely used in a variety of applications. Some of these applications are linear interpolation over a triangle and a triangle inclusion test. The first one is used for so-called <a href="https://en.wikipedia.org/wiki/Shading">shading</a>, and the second one arises in the <a href="https://en.wikipedia.org/wiki/Rasterization">rasterization</a> step when an image in vector graphics format needs to be converted into a raster image.
|
|
|
|
|
|
|
|
|
|
Triangle barycentric coordinates have many important properties, including \em constant and <em>linear precision</em>, <em> the Lagrange property</em>, and <em>positivity inside a triangle</em>. These properties make these coordinates a unique tool in many scientific fields. If we restrict triangle coordinates to one of the edges of a triangle and its supporting line, we get barycentric coordinates with respect to a segment and call them \ref compute_seg_coord "segment coordinates".
|
|
|
|
|
|
|
|
|
|
@ -265,7 +265,7 @@ To plot discrete harmonic coordinates we take \ref wp_plot "the same polygon" as
|
|
|
|
|
The discrete harmonic coordinate function with respect to the indicated vertex with values from zero to one as the colour bar indicates.
|
|
|
|
|
\cgalFigureEnd
|
|
|
|
|
|
|
|
|
|
The last type of generalized barycentric coordinates that we discuss are mean value coordinates \cite cgal:f-mvc-03 proposed by M. Floater in 2003. Based on the <a href="http://en.wikipedia.org/wiki/Mean_value_theorem">mean value theorem</a>, \ref gbc_deg_mean_value_coordinates "these coordinates", unlike Wachspress and discrete harmonic coordinates, are well-defined for arbitrary <em>simple polygons</em>, inherit all the properties of triangle coordinates for any convex polygon, and <em>lack only the positivity property for general concave polygons</em>. Hormann and Floater prove in \cite cgal:bc:hf-mvcapp-06 that these coordinates are positive inside the kernel of a <a href="https://en.wikipedia.org/wiki/Star-shaped_polygon">star-shaped polygon</a>. They are also positive in the closure of any quadrilateral. Like discrete harmonic weights, mean value weights are often used in the context of \ref PkgSurfaceMeshParameterization "triangle mesh parameterization."
|
|
|
|
|
The last type of generalized barycentric coordinates that we discuss are mean value coordinates \cite cgal:f-mvc-03 proposed by M. Floater in 2003. Based on the <a href="https://en.wikipedia.org/wiki/Mean_value_theorem">mean value theorem</a>, \ref gbc_deg_mean_value_coordinates "these coordinates", unlike Wachspress and discrete harmonic coordinates, are well-defined for arbitrary <em>simple polygons</em>, inherit all the properties of triangle coordinates for any convex polygon, and <em>lack only the positivity property for general concave polygons</em>. Hormann and Floater prove in \cite cgal:bc:hf-mvcapp-06 that these coordinates are positive inside the kernel of a <a href="https://en.wikipedia.org/wiki/Star-shaped_polygon">star-shaped polygon</a>. They are also positive in the closure of any quadrilateral. Like discrete harmonic weights, mean value weights are often used in the context of \ref PkgSurfaceMeshParameterization "triangle mesh parameterization."
|
|
|
|
|
|
|
|
|
|
In order to show the particular behaviour of mean value coordinates with an application to concave polygons, we take \ref fig__mv__example "a star-shaped polygon" with ten vertices \f$[v_0, \dots, v_9]\f$, sample its interior and boundary, and plot the coordinate function with respect to the fourth vertex \f$v_3\f$. As the colour bar indicates, the obtained function grows from a slightly negative value to one at the chosen vertex. It is also smooth inside the polygon and linear along all edges.
|
|
|
|
|
|
|
|
|
|
@ -276,7 +276,7 @@ Mean value coordinates with respect to \f$v_3\f$. The colour bar indicates the r
|
|
|
|
|
<b>Interesting fact</b>: all the coordinates discussed in this section and implemented in the package come from one and the same family of generalized barycentric coordinates named <em>3-point family of coordinates</em> \cite cgal:bc:fhk-gcbcocp-06.
|
|
|
|
|
|
|
|
|
|
\section gbc_acknowledgments Acknowledgments
|
|
|
|
|
The authors wish to thank <a href="http://www.inf.usi.ch/phd/schneider/">Teseo Schneider</a> and <a href="http://search.usi.ch/people/5ae37d3d990b431a02b95b0b606da2e6/Schaerfig-Randolf">Randolf Schaerfig</a> for helpful comments and discussions. We also appreciate the great effort invested in this package by our reviewers <a href="http://geometryfactory.com/who-we-are/">Andreas Fabri and Sébastien Loriot</a>. Finally, to create pictures for this manual, we used two programs: <a href="http://www.geogebra.org/cms/en/">Geogebra</a> and <a href="http://www.mathworks.com/products/matlab/">Matlab</a>.
|
|
|
|
|
The authors wish to thank <a href="https://www.inf.usi.ch/phd/schneider/">Teseo Schneider</a> and <a href="https://search.usi.ch/people/5ae37d3d990b431a02b95b0b606da2e6/Schaerfig-Randolf">Randolf Schaerfig</a> for helpful comments and discussions. We also appreciate the great effort invested in this package by our reviewers <a href="https://geometryfactory.com/who-we-are/">Andreas Fabri and Sébastien Loriot</a>. Finally, to create pictures for this manual, we used two programs: <a href="https://www.geogebra.org">Geogebra</a> and <a href="https://www.mathworks.com/products/matlab.html">Matlab</a>.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|