我有3轴的加速度计值(通常只有重力包含介于-1.0和1.0之间的数据):
float Rx;
float Ry;
float Rz;
Run Code Online (Sandbox Code Playgroud)
我做了躯体计算,然后我得到每个轴的角度.
float R = sqrt(pow(Rx,2)+pow(Ry,2)+pow(Rz,2));
float Arx = acos(Rx/R)*180/M_PI;
float Ary = acos(Ry/R)*180/M_PI;
float Arz = acos(Rz/R)*180/M_PI;
Run Code Online (Sandbox Code Playgroud)
然后我在opengl中设置框角度的值
rquad = Arx;
yquad = Ary;
Run Code Online (Sandbox Code Playgroud)
哪个旋转我的盒子:
glRotatef(yquad,1.0f,0.0f,0.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
Run Code Online (Sandbox Code Playgroud)
它适用于半球.我想使用完整的球体,我知道我必须使用Arz值使其工作,但我不知道如何使用它进行此旋转.你可以帮帮我吗?
更新:最终答案在我的情况下:
rquad = -atan2(Rx/R, Rz/R)*180/M_PI;
yquad = -atan2(Ry/R, Rz/R)*180/M_PI;
Run Code Online (Sandbox Code Playgroud) 我正在尝试用定位数据的六边形热图覆盖地图(stat_binhex + ggmap).我可以使用基于正方形的热图(stat_bin2d + ggmap)到达那里,但我认为六边形变体更好.
我明白了
错误:geom_hex()仅适用于笛卡尔坐标
只要我没有将它与地图结合(参见代码),stat_binhex就可以使用我的经度和纬度坐标.
这是我可重复的例子:
library(ggplot2)
library(ggmap)
#set center coordinates
center_longitude<--73.963895
center_latitude<-40.7727524
#define map
map <- get_googlemap(center=c(center_longitude,center_latitude), scale = 2,zoom=12)
#test map in plot
ggmap(map)
#simulate some coordinates deviating from the central points
coords<-data.frame(longitude=rnorm(10000, mean = center_longitude, sd = 0.003),
latitude=rnorm(10000, mean = center_latitude, sd = 0.003))
#Plot longitude and latitude coords with stat_binhex but no map, this works
plt<-ggplot()+
stat_binhex(data=coords,aes(x=longitude,y=latitude))
plt
#I now try to overlay this on the map but this doesn't work
plt2<-ggmap(map)+ …Run Code Online (Sandbox Code Playgroud) 我正在尝试将包含折线的 json 文件读取到 R 中,以便在传单或 ggmap 中进行绘图。该文件为 geojson 格式。
该文件可在以下位置找到:http : //datasets.antwerpen.be/v4/gis/statistischesector.json
我试过了:
library(rgdal)
library(jsonlite)
library(leaflet)
geojson <- readLines("statistischesector.json", warn = FALSE) %>%
paste(collapse = "\n") %>%
fromJSON(simplifyVector = FALSE)
Run Code Online (Sandbox Code Playgroud)
这实际上读入了文件,但似乎格式错误以供进一步处理。
或者:
readOGR(dsn="~/statistischesector.json", layer="OGRGeoJSON")
Run Code Online (Sandbox Code Playgroud)
返回:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open data source
Run Code Online (Sandbox Code Playgroud)
欢迎任何帮助!