小编Atr*_*rav的帖子

如何在vispy中选择距离点击点最近的标记?

vispy库中,我有一个显示为标记的点列表,我想更改最接近单击点的点的颜色(或仅获取其索引)。

我可以通过 event.pos 获取点击点的像素,但我需要它的实际坐标将其与其他坐标进行比较(或获取其他标记的像素点以将其与事件位置进行比较)。

我有这段代码来获取最近的点索引。它接受数组和点的输入(单击一个)

def get_nearest_index(pos,p0):
    count=0
    col =[(1,1,1,0.5) for i in pos]
    dist= math.inf
    ind=0
    for i in range(len(pos)):
        d = (pos[i][0]-p0[0])**2+(pos[i][1]-p0[1])**2
        if d<dist:
            ind=i
            dist=d
    return ind
Run Code Online (Sandbox Code Playgroud)

但问题是我必须在同一坐标系中传递它们。打印出来event.pos返回像素,例如:[319 313]而我的位置在pos数组中是:

[[-0.23801816  0.55117583 -0.56644607]
 [-0.91117247 -2.28957391 -1.3636486 ]
 [-1.81229627  0.50565064 -0.06175591]
 [-1.79744952  0.48388072 -0.00389405]
 [ 0.33729051 -0.4087148   0.57522977]]
Run Code Online (Sandbox Code Playgroud)

所以我需要将其中一个转换为另一个。变换就像

tf = view.scene.transform
p0 = tf.map(pixel_pt)
print(str(pixel_pt) + "--->"+str(p0))
Run Code Online (Sandbox Code Playgroud)

打印出来[285 140 0 1]--->[ 4.44178173e+04 -1.60156369e+04 0.00000000e+00 1.00000000e+00]的内容与点相差甚远。

python simulation vispy

5
推荐指数
1
解决办法
525
查看次数

如何让用户在 c# vsto excel 插件中选择单元格(范围输入)?

我需要的是让用户控制选择一些将在程序中使用的单元格。该界面在许多 Excel 函数中很容易看到,例如向图表插入数据时。

可以轻松访问预先选择的范围,Globals.ThisAddIn.Application.ActiveWindow.RangeSelection但这不是我正在研究的,因为我需要多个这样的范围。我正在visual-studio上尝试这个,有一个Interaction.InputBox函数可以接受字符串,据说相当于Inputboxvba,但是vba的输入框有输入数据类型的参数,而c#输入框没有。

与此等效的 VBA 是

Dim rngX as Range
Set rngX = Application.InputBox("Select a cell or a range", "Input Cells", Type:=8)
Run Code Online (Sandbox Code Playgroud)

Type:=8 将使输入框接受范围输入。但我需要在 C# 中执行此操作(使用 Visual Studio),并且 C# 的 Inputbox 方法没有像 VBA 这样的输入类型。

c# excel vba vsto excel-addins

3
推荐指数
1
解决办法
1389
查看次数

标签 统计

c# ×1

excel ×1

excel-addins ×1

python ×1

simulation ×1

vba ×1

vispy ×1

vsto ×1