You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

极坐标转换后直线与圆相交异常问题及临时解决方法

极坐标转笛卡尔坐标后直线与圆相交的精度问题

我有一组极坐标数据集,其中包含生成直线的点坐标。需要让这些直线与半径为18的圆相交,因此先将极坐标转换为笛卡尔坐标,但最终仅部分直线能正确与圆相交。将圆半径调整为17.999即可解决问题,推测是极坐标转笛卡尔坐标过程中存在精度误差。

可复现代码

# 数据集
Boundaries <- data.frame(UE = c(127,127,128,128,128,129,129,129,129,129),
                    ID_Line = c(1,1,1,1,1,1,1,1,2,2), 
                    ID_Point = c(1,2,1,2,3,1,2,3,1,2),
                    Azimut = c(10,120,120,90,230,120,90,230,90,270),
                    Distance = c(18,18,18,5,18,18,5,18,5,18)
                    )

library(tidyverse)
library(useful)

# 极坐标转笛卡尔坐标
Boundariesxy <- as_tibble(Boundaries) %>%
  mutate(Theta = 2*pi*Azimut/360,
         x = pol2cart(Distance, Theta, degrees=F)[["y"]],
         y = pol2cart(Distance, Theta, degrees=F)[["x"]])


library(sf)
# 转换为sf对象
Boundaries_sf <- st_as_sf(Boundariesxy,
                          coords = c('x', 'y')) %>%
  st_set_crs("102010")  %>%
  group_by(UE, ID_Line)  %>%
  summarise() %>%
  ungroup()

# 转换为线要素
Bound_lines <- st_cast(Boundaries_sf, "LINESTRING")

# 创建圆形多边形
Point <- data.frame(
  Plot = c("A"),
  x = c(0),
  y = c(0))
# 将圆心转换为米制CRS的空间对象
Point_sf <- st_as_sf(Point,
                     coords = c('x', 'y')) %>%
  st_set_crs("102010") %>%
  st_convex_hull()
# 生成缓冲圆
Circle_st_18 <- st_buffer(Point_sf,18)
Circle_st_17999 <- st_buffer(Point_sf,17.999)

library(lwgeom)
# 按UE分别执行直线与圆的分割操作
B127 <- Bound_lines[which(Bound_lines$UE==127),]
plot(B127)
Split_127 <- st_split(Circle_st_18,B127)
plot(Split_127)
Split_127_2 <- st_split(Circle_st_17999,B127)
plot(Split_127_2)
Poly_127 <- (Split_127 %>% st_collection_extract(c("POLYGON")))
st_area(Poly_127)

B128 <- Bound_lines[which(Bound_lines$UE==128),]
plot(B128)
Split_128 <- st_split(Circle_st_18,B128)
plot(Split_128)
Split_128_2 <- st_split(Circle_st_17999,B128)
plot(Split_128_2)
Poly_128 <- (Split_128 %>% st_collection_extract(c("POLYGON")))
st_area(Poly_128)

B129 <- Bound_lines[which(Bound_lines$UE==129),]
plot(B129)
Split_129 <- st_split(Circle_st_18,B129)
plot(Split_129)
Poly_129 <- (Split_129 %>% st_collection_extract(c("POLYGON")))
st_area(Poly_129)
Split_129_2 <- st_split(Circle_st_17999,B129)
plot(Split_129_2)

效果对比图

  • 半径18时的分割效果:
    半径18时的分割效果
  • 半径17.999时的分割效果:
    半径17.999时的分割效果

内容的提问来源于stack exchange,提问作者Antonello Salis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 23:05:14