1

I tried to draw a set of octahedra by vpython, it showed, however, the scene looks don't like a 3D object, it looks just like a colored shadow, whatever how I rotate it. I have no idea how to fix this problem.

from vpython import *
from itertools import *
import numpy as np

faces = [[vertex(pos=vec(*v)) for v in np.diag(i)] 
          for i in product(*[(-1,1)]*3)]

octa = compound([triangle(vs=i) for i in faces])
octa.visible=False

centers = [vec(*i) for i in product(*[(-1,0,1)]*3) if sum(i)%2==0]
octa_group = compound([octa.clone(pos=i) for i in centers])

octa_group.color = vec(0.5,0.9,1)
#octa_group.opacity = 0.5

while True:
    rate(30)

It shows the scene as follows. enter image description here

I expect an effect like this (It seems no problem with built-in 3D objects like box) enter image description here

4
  • The only "effect" in the second scene is that there is one colour per face orientation: light for the faces facing us, medium for the faces facing up, and dark for the faces facing to our right. Perhaps you can display your scene with one colour per face orientation as well? One way to characterise the orientation of a face is to calculate a unit-norm normal vector for the face. Commented Feb 12, 2024 at 0:14
  • Unrelatedly, using from something import * instead of import something is not a great habit. If two functions from two modules have the same name, one of them will shadow the other; in any case it becomes hard for someone who reads your code to understand which function comes from where. I suggest using import vpython; import itertools or import vpython as vpy; import itertools as it or some variant, so that you then write itertools.product or it.product, just like you did with numpy (import numpy as np and not from numpy import *) Commented Feb 12, 2024 at 0:17
  • Presumably you don't need to compute the surface normal vectors yourself, and can adjust the lightsource so it does the work for you: glowscript.org/docs/VPythonDocs/light.html Commented Feb 12, 2024 at 0:22
  • It looks like you have not specified normals for the triangles, which will lead to the washed-out objects you display. Commented Mar 6, 2024 at 3:49

0

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.