如何绘制一个具有虚化和正确方向角的椭圆?

问题描述 投票:0回答:1

我想绘制一个椭圆,基于两个焦点f1和f2以及第三个点。但由于某些原因,我计算的给定角度的椭圆的方向没有正确显示。

我是不是漏掉了什么基本的东西?为什么在给定角度为pi4的情况下,散景不对椭圆进行定位?

这是我的示例代码。

import numpy as np
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import Range1d
output_notebook()

f1 = np.array([0,0])
f2 = np.array([3,3])
point = np.array([1,3])

tools = "hover, box_zoom, undo, crosshair"
p = figure(tools=tools)
p.circle(f1[0], f1[1], radius = 0.05, alpha=0.5)
p.circle(f2[0], f2[1], radius = 0.05, alpha=0.5)
p.circle(point[0], point[1], radius = 0.05, color='red')

center = (f2 - f1)/2 + f1
print(center)

angle = np.arctan2((f2 - f1)[1], (f2 - f1)[0])
print(np.rad2deg(angle))
# minor axis
a = (np.linalg.norm(f2-point) + np.linalg.norm(f1-point))/2
# major axis
c = np.linalg.norm((f2 - f1)/2)
# b = np.sqrt(a**2 - c**2)/2
b = 0.2

p.circle(center[0], center[1], radius = 0.05, color='orange')
p.ellipse(x=center[0], y=center[1], width=2*a, height=2*b, angle=angle, fill_color="yellow", fill_alpha = 0.4)
p.x_range = Range1d(-2, 4)
p.y_range = Range1d(-2, 4)
show(p)

enter image description here

python geometry bokeh ellipse
1个回答
2
投票

这是个挺难的问题,还没有解决。https: /github.combokehbokehissues7965

tl;dr:角度基本上使用的是屏幕像素比例,与数据范围比例不一致。在你的特殊情况下,是工具栏和轴 "挤压 "了主图区域。如果你把它们去掉,那么这个区域就会完全方正,角度也会正确。

© www.soinside.com 2019 - 2024. All rights reserved.