Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement @@spoly #129

Open
msdemlei opened this issue Aug 13, 2024 · 5 comments
Open

Implement @@spoly #129

msdemlei opened this issue Aug 13, 2024 · 5 comments

Comments

@msdemlei
Copy link
Contributor

Currently, the @@ operator only works for scircles (and I think spoints). It is occasionally useful to also obtain the centroid of a polygon.

I have not thought about this in depth, but I think it ought to be fine just to compute the mean of the vertexes; what with poles and the stitching line, this has quite a few subtleties, too. What I do in some non-DB code is this:

		vertices = [numpy.array(mathtricks.spherToCart(p.x, p.y))
			for p in self.points]
		center = numpy.average(vertices, axis=0)
		center = center/(center@center)
		return mathtricks.cartToSpher(center)

– that is, I'm taking the mean of the unit sphere coordinates of the vertices and then convert the resulting vector (after normalisation) to spherical coordinates. Do people think this is the right way to do that?

@esabol
Copy link
Contributor

esabol commented Aug 13, 2024

@msdemlei : There was an attempt at implementing this in PR #33, so you should read through that. @vitvpp closed that issue due to "conceptual problems", presumably related to whether such a function should calculate the true centroid in 3D space or its projection on the unit sphere surface (the moment?).

At the time, my research into the issue led me to the following links:

https://stackoverflow.com/questions/19897187/locating-the-centroid-center-of-mass-of-spherical-polygons (but especially this answer: https://stackoverflow.com/questions/19897187#answer-38201499)
https://github.com/chrisveness/geodesy/blob/8f4ef33d/latlon-nvector-spherical.js#L783 (a JavaScript implementation of that answer)

@msdemlei
Copy link
Contributor Author

msdemlei commented Aug 13, 2024 via email

@esabol
Copy link
Contributor

esabol commented Aug 13, 2024

@msdemlei wrote:

One would have to establish the winding direction of the particular polygon before running
Hatch's code.

The JavaScript implementation I linked to seemingly just negates the angle of the vector to handle that? It has the following code comment: "if centreV is pointing in opposite direction to 1st vertex (depending on cw/ccw), negate it".

Can anyone point to code in pgsphere that would already do that?

That sounds like issue #2. Nobody has tackled it yet.

@esabol
Copy link
Contributor

esabol commented Aug 14, 2024

By the way, there's been no sign of @vitcpp on GitHub since June 3. I hope he's ok!

@vitcpp
Copy link
Contributor

vitcpp commented Aug 14, 2024

Dear All,

I'm ok and online, thanks! Sorry for the delayed answer. There was an attempt to implement centroid() function for an array of points. We faced some "conceptual" problems. The solution was incomplete at that moment, I decided to close it. It is not a problem to reopen.

There are some problems with the centroid() function that takes the array of points:

  • Which coordinate system to use. I guess, the spherical coordinate system is of interest. But we may create both for spherical 2d and 3d spaces.
  • In case of spherical 2d the result may be the following: undefined, 1 point, continuum of points (line). It was not evident what to return in all these cases. The result is indefined - 6 points, where each pair of points are on the opposite edges if axis lines. Continuum of points (line) - when two points are on two opposite edges of a meridian line.
  • Naming convention: center, centroid, ...

We have to decide which result to return in each case. If needed, we can reopen the issue #33.

For spoly I do not see such issues because spoly is a closed figure with interior. There should be no conceptual problems to find the center of the polygon interior on spherical 2d surface.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants