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

Inverted params #89

Closed
mblasi opened this issue Jun 13, 2022 · 1 comment
Closed

Inverted params #89

mblasi opened this issue Jun 13, 2022 · 1 comment

Comments

@mblasi
Copy link

mblasi commented Jun 13, 2022

Hi, I'm pretty sure about inverted params here:

https://github.com/golang/geo/blob/master/s2/latlng.go#L36

// LatLngFromDegrees returns a LatLng for the coordinates given in degrees.
func LatLngFromDegrees(lat, lng float64) LatLng {
	return LatLng{s1.Angle(lat) * s1.Degree, s1.Angle(lng) * s1.Degree}
}

Not sure about the formule, but I tested it with a known polygon and a couple of known points, and it works as expected inverting the params, teste follows:

package main

import (
	"fmt"
	"github.com/golang/geo/s2"
	"github.com/twpayne/go-polyline"
	"go.opencensus.io/plugin/ochttp"
)

func main() {

	//Ituzaingo
	polyline := "|qkrEfpmeJkAsDwDoEcAq@uDWgDCoAw@cEwJiBe@aI_@_@KiAk@wAc@mGAyDg@wDvAcWkBsAa@{@_@gAk@yFkE}FsEaPsEkGgBiFyAaBW_@G}BmCqD{A_EsBqBeBwAaCoFsJiAeB}MsSu@k@mCsByQw^sE{FgAoDkBkQ{CuOeL}QfCiDhLoOjCqDtD_FnAcB`CcDxBsC`RyVhBrB`BpBdBrBdBhB`D_ExBsCjCgDjKiNjGeIbC_DfCaDdG_IlCkD`G_IfB_CdHkJvHyJjDmExCyD~@mAnBiChDoExEkGV[dG_IdC_DbCaD`DgEnBcCjBgCZa@lCoDxAeBRWtAkBhAuAv@_@\\KRETCfBIjAEhAGj@Cl@?j@Bd@Db@H`ElArDbAxCr@vDz@tDx@|FhA|FbAtDl@zDh@|Dh@~Ch@`@FtDl@zDn@pDj@vDp@`En@hFz@hC^|@N~Ch@vCd@vEt@tEr@tCd@fARr@@xCl@H@bDh@n@HRDH@H@b@H`AP|Cd@bBXtB\\jC`@hARvAT^F`BVb@F~Ch@\\D`C`@p@JnGbAnCb@h@HtDr@pEr@j@JJ@zB\\nB\\nANdEr@bFr@fDj@pDp@nARXDl@JrIrAd@HfFv@xDn@`BTxDj@`BTpAT|ATfBX|Cd@nB\\z@RdBRdBVdCb@ZDwCrDmB`CaBpBgB~BcBxB}AnBiAxAeBxBiAzAMP_CtCmB`CuAfBwC~D{BjCoBpC_BhBeArAo@x@aBvBY\\yAjB[b@gA~AeApAW\\aBpBqBhCaBrB_BtBsBnC{AjBq@x@q@x@}ApBa@f@mA~AcC~CgCbDsCpD}BvCUXsCpDsAdBm@v@kBbCm@t@c@j@EDEFUZwD~E_BjB_@j@cC`DKNuBhCs@|@[^uC~DqDlEeAtA{BxCcC`D_CzCaC~CkCjDoCpDwCtDqCjDY`@a@j@wBnCc@h@}CzDkEpF}AlBOPqA`B{@dAsC~D]`@mD|E_DtDwBnC}BrCmChDkC`DuAfBsX`^m`@lg@??"

	points := decode(polyline)

	regionPoints := []s2.Point{}

	for _, bound := range points {
		lat := bound[0]
		lng := bound[1]
		fmt.Printf("[%v, %v],\n", lng, lat)
		regionPoints = append(regionPoints, s2.PointFromLatLng(s2.LatLngFromDegrees(lng, lat).Normalized()))
	}
	lat := points[0][0]
	lng := points[0][1]
	fmt.Printf("[%v, %v]\n", lng, lat)
	regionPoints = append(regionPoints, s2.PointFromLatLng(s2.LatLngFromDegrees(lng, lat).Normalized()))

	loop := s2.LoopFromPoints(regionPoints)
	loop.Normalize()

	fmt.Printf("Polyline: %s\n", polyline)

	point1 := s2.PointFromLatLng(s2.LatLngFromDegrees(-58.435703, -34.606762).Normalized())
	point2 := s2.PointFromLatLng(s2.LatLngFromDegrees(-58.68175, -34.64108).Normalized())

	fmt.Printf("point 1 contained in loop1: %v (should be false)\n", loop.ContainsPoint(point1))
	fmt.Printf("point 2 contained in loop1: %v (should be true)\n", loop.ContainsPoint(point2))
}

func decode(ncodedP string) [][]float64 {
	points, _, err := polyline.DecodeCoords([]byte(ncodedP))
	if err != nil {
		fmt.Printf("Error decoding: %s", err.Error())
	}

	return points
}
@mblasi
Copy link
Author

mblasi commented Jul 20, 2022

I worked on that again, and it looks that the problem was the polygon definition. My fault.

@mblasi mblasi closed this as completed Jul 20, 2022
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

1 participant