mlab 中的简单箭头 mayavi/tvtk 奇怪的行为(看起来像一个错误) [英] Simple arrow mayavi/tvtk in mlab weird behaviour (looks like a bug)

查看:24
本文介绍了mlab 中的简单箭头 mayavi/tvtk 奇怪的行为(看起来像一个错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 mlab 中做一个简单的箭头来指向图表上的不同区域.考虑这个例子:

I am trying to do a simple arrow in mlab to point to different areas on the graph. Consider this example:

fig = mlab.figure( bgcolor=(0, 0, 0))
b=visual.Box(x=0, y=10, z=10)
visual.set_viewer(fig)
b=visual.Box(x=0, y=10, z=10)
b2=visual.Box(x=10,y=10,z=10, color=(0,0,1))
a=visual.Arrow(x=10,y=10,z=10, color=(1,0,0))

所以在我看来,箭头应该从蓝色框中出现,但它过着自己神秘的生活,并且完全处于关闭状态.这很奇怪,盒子被定位并绑定到网格(所以如果我把 b 放到 x=10,y=10,z=10 两个盒子将被并置),但是箭头不是.这是错误还是功能?

So in my mind the arrow should appear from the blue box, however it lives it's own misterious life and is located absolutely off. That is very strange that boxes are located and bound to the grid (so if I put b to x=10,y=10,z=10 the two boxes will be collocated), however the arrow is not. Is this a bug or a feature?

更新:

我正在尝试修复上述问题,发现箭头的行为非常奇怪.这就是我所做的(在 ipython 中进行交互):

I was playing around trying to fix the above and found the behaviour of the arrow very weird. This is what I do (in ipython for interaction):

from mayavi import mlab
from tvtk.tools import visual
fig=mlab.figure( bgcolor=(0, 0, 0))
visual.set_viewer(fig)

首先将盒子放在画布上的某个位置作为参考:

First put the box somewhere on canvas as a reference:

b=visual.Box(x=10,y=4,z=1)

然后我想要一个从盒子里伸出来的箭头:

Then I want an arrow sticking out of the box:

a=visual.Arrow(x=10,y=4,z=1)

没有解决(与问题的第一部分相同):

Didn't work out (same as the first part of the question):

现在,让我们无故改变锥体的长度

Now, let's change length of the cone without reason

a.length_cone

返回

0.35

让我们改变它

a.length_cone=0.5

现在箭头从盒子里伸出来了

Now the arrow is sticking out of the box as it should be

将锥体的长度改回 0.35,看看这是否会将箭头改回错误的位置

Change length of the cone back to 0.35 to see if this changes the arrow back to wrong position

a.length_cone=0.35

不,箭头留在它应该在的框中.这看起来像是一个错误.

No, the arrow stays in the box where it should be. This looks like a bug.

推荐答案

玩转箭头,我写了下面的函数来生成一个从 x1,y1,z1x2 的箭头,y2,z2

Playing around with arrow, I wrote the following function to generate an arrow from x1,y1,z1 to x2,y2,z2

def Arrow_From_A_to_B(x1, y1, z1, x2, y2, z2):
    ar1=visual.arrow(x=x1, y=y1, z=z1)
    ar1.length_cone=0.4

    arrow_length=np.sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2)
    ar1.actor.scale=[arrow_length, arrow_length, arrow_length]
    ar1.pos = ar1.pos/arrow_length
    ar1.axis = [x2-x1, y2-y1, z2-z1]
    return ar1

这篇关于mlab 中的简单箭头 mayavi/tvtk 奇怪的行为(看起来像一个错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆