是否有用于创建带有尖椭圆或透镜的图的自定义几何或函数?

Is there a custom geometry or function for creating a plot with a pointed ellipse or lens?

我已经为我的大学项目测量了大约 2000 颗种子的长度和宽度。我想绘制它们的形状以便于解释视觉表示。

它们是椭圆形的,但两端是尖的,因此椭圆函数不太适用。

请参阅图片了解种子形状。

这里是帮助您入门的部分答案。您描述的形状称为“透镜”,是两个等半径圆的交点。请参阅 https://mathworld.wolfram.com/Circle-CircleIntersection.html for derivations of equations for its dimensions, areas etc. It is also formed byt two "segments" back to back. We can use the equations from here https://mathworld.wolfram.com/CircularSegment.html 了解线段的高度和宽度与半径的关系。

使用这些方程式,我们可以绘制提供所需高度和宽度交点的相交圆:

height = 10
width = 3

a = height
h = width/2

R = function(a, h) (a^2/(8*h)) + h/2 # radius of circles
D = function(r, h) 2*r - 2*h # distance between circle centers
r = R(a, h)
d = D(r, h)

plot(NA, asp=1, xlim=c(-h,h), ylim=c(-a/2,a/2) )
plotrix::draw.circle(-d/2,0,r)
plotrix::draw.circle(d/2,0,r)

我把它留作练习,供您使用创建一个仅在交点周围绘制多边形的函数(我确实说过这是部分答案:-)

编辑:添加 coord_fixed() 以确保纵横比正确,以及一些虚拟点以拉伸 canvas。

这个有用吗?这是背靠背 geom_curves().

#Whosebug seed lens geom_curve
#question from:
#
#assistance from:
#

library(tidyverse)

df <- tribble(
  ~seed, ~h, ~w, ~row,
  #----|----|---|---
  "Oak", 5,  4,   1,
  "Soy", 2,  2,   2,
  "Rye", 4,  1,   3
)


df <- df %>% mutate(curvature = w/h)

ggplot() + 
  lapply(split(df, 1:nrow(df)), function(dat) {
    geom_curve(data = dat, aes(x = row, y = -h/2, xend = row, yend = h/2), curvature = dat["curvature"]) }
  ) +
  lapply(split(df, 1:nrow(df)), function(dat) {
    geom_curve(data = dat, aes(x = row, y = h/2, xend = row, yend = -h/2), curvature = dat["curvature"]) }
  )+
  geom_point(aes(x=-2, y=0), colour = NA)+
  geom_point(aes(x=5, y=0), colour = NA)+
  geom_label(data = df, aes(x=row, y = 0, label = seed))+
  coord_fixed(ratio = 1) +
  #coord_cartesian(xlim = c(-2,nrow(df)+2))
  ylab(NULL)+


ggsave("seeds.png")

结果: