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

A circle is deformed by rotation around its center by the spin() function #1576

Open
jeanlobry opened this issue Jul 24, 2024 · 5 comments
Open

Comments

@jeanlobry
Copy link

jeanlobry commented Jul 24, 2024

Dear all,

I'm unsure whether this is a bug or or a feature, or if I'm missing something obvious. Here is my MRE:

xlon <- +5.220700 ; ylat <- +46.21010
FRBOUB <- terra::vect(cbind(xlon, ylat), crs = "EPSG:4326")
cercle <- terra::buffer(FRBOUB, width = 25*10^3, quadsegs = 100)
rotated <- terra::spin(cercle, 45, xlon, ylat)
terra::plot(cercle, las = 1, xlab = "Longitude", ylab = "Latitude")
terra::points(FRBOUB, pch = 3, cex = 2)
terra::sbar(type = "bar", below = "km")
terra::north()
terra::lines(rotated, col = "red")

The result is very confusing for me, if this is the intented behaviour I suggest that this should be documented in the spin() function.

Very best and thanks for this wonderful package,

Pr. Jean R. Lobry

P.-S. My sessionInfo()

R version 4.3.2 (2023-10-31)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.4.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Paris
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] leaflet_2.2.2     boot_1.3-28.1     terra_1.7-71      dichromat_2.0-0.1

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.7          highr_0.10              compiler_4.3.2          crayon_1.5.2           
 [5] Rcpp_1.0.11             zip_2.3.0               jquerylib_0.1.4         yaml_2.3.7             
 [9] fastmap_1.1.1           readr_2.1.4             R6_2.5.1                knitr_1.44             
[13] htmlwidgets_1.6.4       tibble_3.2.1            leaflet.providers_2.0.0 pillar_1.9.0           
[17] tzdb_0.4.0              readODS_2.1.0           rlang_1.1.1             utf8_1.2.4             
[21] stringi_1.7.12          xfun_0.44               pkgload_1.3.4           cli_3.6.1              
[25] magrittr_2.0.3          crosstalk_1.2.1         grid_4.3.2              digest_0.6.33          
[29] rstudioapi_0.15.0       hms_1.1.3               lifecycle_1.0.3         vctrs_0.6.4            
[33] evaluate_0.22           glue_1.6.2              cellranger_1.1.0        codetools_0.2-19       
[37] fansi_1.0.5             rmarkdown_2.25          tools_4.3.2             pkgconfig_2.0.3        
[41] ellipsis_0.3.2          htmltools_0.5.7        `
@edzer
Copy link
Contributor

edzer commented Jul 26, 2024

My guess: buffer computes a geometry on a sphere, spin rotates it in R2, in a Cartesian space, not on a sphere.

@jeanlobry
Copy link
Author

Yes but my rotated object is not in a Cartesian space...

@edzer
Copy link
Contributor

edzer commented Jul 26, 2024

It got rotated in a Cartesian space.

@edzer
Copy link
Contributor

edzer commented Jul 26, 2024

library(terra)
# terra 1.7.78
library(sf)
# Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
xlon <- 0 ; ylat <- -90
v = vect("POLYGON((0 -80,-120 -80,120 -80,0 -80))")
crs(v) = 'EPSG:4326'
spin(v, 120, xlon, ylat) |> sf::st_as_sf() |> sf::st_geometry() -> x
x[[1]]
# POLYGON ((8.660254 -95, 68.66025 8.923048, -51.33975 -198.923, 8.660254 -95))

note the latitudes outside +/- 90.

@jeanlobry
Copy link
Author

Thanks, you example illustrates better my point. Should't spin() be renamed spin2D() or at least restricted to planar geometries?

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

2 participants