2
$\begingroup$

I am having trouble working out the generalisation of this stack overflow post, for an n sided regular polygon. I would simply comment on the linked post, but I unfortunately don't have enough reputation.

The question is relevant to me because I am creating an online survey design tool, where one of the survey components will be a polygon with labeled vertices, featuring a draggable dot placed in the center of the shape. The dot is drag-and-drop-able, where the proximity to each vertex encodes the respondents association towards that vertex. Consider the following example.

enter image description here

For triangles, I can simply use the methods discussed in the above link. In the more general case, there are problems with methods where percentages are directly proportional to distance from the vertex. Consider a pentagon, where the dot is placed very near towards a vertex. The human interpretation would approach (100%, 0%, 0%, 0%, 0%), but when using methods based on vertex distance, I don't get the intuitive percentages, because distance to opposing vertices exceed the distance to adjacent vertices (implying lower %'s, when actually I don't associate highly with the adjacent, or the opposite).

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ Could you add what you have tried please? $\endgroup$
    – person
    Jul 21, 2022 at 7:39
  • $\begingroup$ You can find the weighting inside triangle $𝐴𝐵𝑂$, where $𝐴𝐵$ is the side nearest to the point and $O$ the centre of the polygon, and then replace $O$ with ${1\over 𝑛}(𝐴+𝐵+\dots)$. But this is only one of the many possible solutions. You could also choose any three vertices and find the weightings with respect to them. $\endgroup$ Jul 21, 2022 at 9:19
  • $\begingroup$ The method outlined in my comment above shouldn't be so far from what you need. In your pentagon, for instance, the weights of the lowest point are approximately $(0.1, 0.1, 0.3, 0.4, 0.1)$. $\endgroup$ Jul 25, 2022 at 21:48

1 Answer 1

1
$\begingroup$

It does not directly generalize to $N$-sided polygons; it only applies to the simplex in $\mathbb{R}^K$, which is a line in 1D, triangle in 2D, a tetrahedron in 3D, and so on. This is because it is based on the barycentric coordinate system, and is essentially linear interpolation between the vertices.

One way to generalize linear interpolation to a regular $N$-sided polygon, would be to split the polygon into $N$ triangles, by adding a new "vertex" at the center (with its value being the average of the vertices'). Then, each point within the polygon would be interpolated between two original vertices and the center point. This would be piecewise linear interpolation.


Another way is to drop the linear interpolation, and generalise the barycentric coordinate approach, by using a monotonically decreasing positive weighing function $$w(r) = \frac{1}{r^\lambda} = r^{-\lambda}, \quad 0 \lt \lambda \in \mathbb{R}$$ where $r$ is the distance to the vertex this weight corresponds to. (In barycentric coordinates, the sum of the coordinates is always $1$, and thus logically match "weights" of the simplex vertices.) Note that this must tend to infinity at $w(0)$, so that the interpolated value at each vertex is the value at that vertex. The real positive parameter $\lambda$ defines the "stiffness" or "steepness" of the interpolation, with $\lambda = 1$ a good starting point.

If each vertex is associated with value $c_i$, located at $(x_i, y_i)$, then the interpolated value of $c$ at $(x, y)$ is calculated outside any of the vertices themselves as $$\begin{aligned} w_i &= w\left(\sqrt{ (x - x_i)^2 + (y - y_i)^2 }\right) \\ c &= \left( \frac{1}{\sum_i w_i} \right) \left( \sum_i c_i w_i \right) \\ \end{aligned}$$ At vertex $i$, $w_i = \infty$, and the above leaves $c$ undefined; there $c = c_i$.


Other interpolation approaches also exist, but the two above ones are the closest ones to "generalize" the barycentric coordinate linear interpolation OP referred to that I can think of.

In particular, any way to map $(x, y)$ to $N$ (analogs of) barycentric coordinates $w_1$, $w_2$, $\dots$, $w_N$, such that $\sum_{i=1}^N w_i = 1$, lets you calculate the interpolated value $c$ simply via $c = \sum_{i=1}^n c_i w_i$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .