为了解决this problem关于两个椭圆的重叠,我们从椭圆的内部近似椭圆。事实上,椭圆是凸的,我们通过连接周边上的连续点来构造一条路径。这给出了椭圆中包含的多边形。
所以我们最后找到的面积必然小于真实面积:我们得到了面积的下限。
如何构造一个包含椭圆(当然还要近似它)的多边形,以获得上限?通过取小块切线来构造一个包络线似乎并不容易。
最佳答案
使用this answer中给出的椭圆公式构造切线并不太难。 。它以参数形式给出椭圆;要获取切线的斜率,请使用 (dy/dtheta)/(dx/dtheta)
,即
slopes <- (-a * sin(theta) * sin(angle) + b * cos(theta) * cos(angle))/
(-a * sin(theta) * cos(angle) - b * cos(theta) * sin(angle))
那么拦截来自intercepts <- y - slopes*x
,其中x
和y
来自椭圆上的点。
最后,您将连续对这些切线相交以获得外部多边形的顶点。这是一个完整的解决方案:
innerouter <- function(x0, y0, a, b, angle, n = 360) {
angle <- angle/360 * 2 * pi
theta <- c(seq(0, 2 * pi, length.out = n), 0)
slopes <- (-a * sin(theta) * sin(angle) + b * cos(theta) * cos(angle))/
(-a * sin(theta) * cos(angle) - b * cos(theta) * sin(angle))
crds <- cbind(a * cos(theta) * cos(angle) - b * sin(theta) * sin(angle) + x0,
a * cos(theta) * sin(angle) + b * sin(theta) * cos(angle) + y0)
intercepts <- crds[,2] - slopes*crds[,1]
i <- 1:(n-1)
x <- (intercepts[i] - intercepts[i+1])/(slopes[i+1] - slopes[i])
y <- slopes[i]*x + intercepts[i]
outer <- cbind(c(x, x[1]), c(y, y[1]))
inner <- crds
list(inner = inner, outer = outer)
}
both <- innerouter(0,0,5, 10, 45, n=10)
plot(both$outer, col = "green", type = "l")
lines(both$inner, col = "red")
创建于 2023 年 5 月 10 日 reprex v2.0.2
关于r - 如何从外部近似椭圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76221986/