带有Vpython 7.5.1的Python 3.7.4。
如果不是“(1,0,0)”这样的“简单”矢量,则它显示的场景没有箭头,或者根本不显示。
我想显示一个三角形,并显示一个从表面描绘法线的箭头。程序显示带有箭头和球体的坐标轴。当我尝试使用标准箭头中的任何值时,显示有时会失败,有时会显示,但不会显示标准箭头。如果我输入向量(1,0,0)或(0,1,0)等,它会起作用,但不适用于(2,2,0)
尝试了几天我能想到的一切
###################################
##
from vpython import * ##
import numpy as np ##
##
###################################
# Python 3.7.4 with Vpython 7.5.1
#=====================================================================================================##
##
def axisArrows(): ##
# ##
al = 10.0 #arrow length ##
Xarrow = arrow(pos=vector(0,0,0), shaftwidth=.2,length=al, axis=vector(1,0,0), color=color.red) ##
Yarrow = arrow(pos=vector(0,0,0), shaftwidth=.2,length=al, axis=vector(0,1,0), color=color.green) ##
Zarrow = arrow(pos=vector(0,0,0), shaftwidth=.2,length=al, axis=vector(0,0,1), color=color.blue) ##
sphere(radius=0.5) ##
return ##
#=====================================================================================================##
# Scene
# =====
canvas(title='Triangles', background=vector(.8,.9,.05), x=350, y=0, width=2000, height=1100)
# AxisArrows
# ==========
axisArrows()
# Triangle Coords
# ===============
va=vector(-5,7,-5)
vb=vector(7,-3,2)
vc=vector(5,7,0)
vd=vector(5,7,0)
# Convert coords to numpty array
# ==============================
p1 = np.array([va.x,va.y,va.z])
p2 = np.array([vb.x,vb.y,vb.z])
p3 = np.array([vc.x,vc.y,vc.z])
# Calc average and normal (vn, normal to triangles plane)
# =======================
#
# normal (a vector)
N = np.cross(p2-p1, p3-p1)
print("p1= ", p1, "N = ", N)
N=N/50
vn = vector(N[0],N[1],N[2]) # vector for normal arrow
print(" vn= ", vn)
# average (a vector)
average = (va+vb+vc+vd)/4
print(" Average = ", average)
sphere(radius=.5,pos=average) # ******************
# Display the norm arrow ******************
N_arrow = arrow(pos=vector(average), shaftwidth=.2, length=4, axis=vector(0,0,2), color=color.blue)
# ******************
# ******************
# vector(0,0,2) shows, vector(0,2,2) doesn't
# Create a triangle (quad with two vertices the same) most value don't work
# =================
a = vertex(pos=va,color=color.red)
b = vertex(pos=vb,color=color.green)
c = vertex(pos=vc,color=color.blue)
d = vertex(pos=vd,color=color.white)
tr1 = quad(v0=a,v1=b,v2=c,v3=d)
最佳答案
好的,这绝对是VPython的错误。非常奇怪的是,尽管VPython 7使用相同的GlowScript图形库,但它并未在GlowScript VPython中显示。归结起来,以下两个要执行的语句中的第二个将产生变形的箭头:
箭头(pos = vec(1,0,0),轴= vector(1,1,0),color = color.red)
箭头(pos = vector(0,0,0),axis = vector(-1,1,0),color = color.green)
而且,如果您使第一个箭头语句具有axis = vec(0,1,0),则第二个箭头甚至都不会出现,如您所见。目前,我(1)不知道出了什么问题,并且(2)以前没有报告过此错误,这很奇怪。
我要评论一下,对于VPython问题,最好将其发布到VPython论坛,那里有更多的VPython用户将看到您的问题,而不是是否发布到stackoverflow:
https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users
关于python - vpython Axis 问题,仅接受矢量(1,0,0),即一个轴,而不是(2,2,1),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59934858/