1

Python 3.7.4 with Vpython 7.5.1. When not a 'simple' vector such as (1,0,0) it displays the scene without the arrow or does not display at all. I want to display a triangle and show an arrow depicting the normal from the surface. The program displays the coordinate axes with arrows and a sphere. When I try any values in the norm arrow the display sometimes fails, and sometimes does display but not with the norm arrow. It works if I put in vectors (1,0,0) or (0,1,0) etc, but not for eg (2,2,0) Tried everything I can think of for several days

###################################
                                 ##
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)
1
  • I don't have an answer yet, but I discovered that if I comment out the Yarrow statement the program works properly. To be continued. Commented Feb 4, 2020 at 21:21

1 Answer 1

0

Ok, it's definitely a VPython bug. VERY oddly, it doesn't show up in GlowScript VPython, despite the fact that VPython 7 uses the same GlowScript graphics library. Boiling it down, the second of the following two statements to be executed produces a deformed arrow:

arrow(pos=vec(1,0,0), axis=vector(1,1,0), color=color.red) arrow(pos=vector(0,0,0), axis=vector(-1,1,0), color=color.green)

And if you make the first arrow statement have axis=vec(0,1,0), the second arrow doesn't even appear, as you saw. At the moment I (1) have no idea what's wrong and (2) it's very strange that this bug has not previously been reported.

I'll comment that for VPython questions it's better to post to the VPython forum, where there are many more VPython users who will see your question than if you post to stackoverflow:

https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users

Sign up to request clarification or add additional context in comments.

1 Comment

This was fixed long ago.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.