Found this link which goes some way to answering the issue.
I’m using Python 3.12.1 and vpython 7.6.4
[Getting error when compounding two objects (google.com)]
https://groups.google.com/g/vpython-users/c/6ojA7FxcILA
Looking at the threads I’m thinking my versions don’t work together well…
Maybe my best route forward is to change over to Processing 4 for animations?
From my previous post on this topic, I have started using VScode and gone through how to use the debugger examples.
I’ve also read up (using Google) on what the error code :
-line 3262, in handle_event obj._axis.value = obj._size._x*norm(obj._axis)
TypeError: unsupported operand type(s) for *: ‘float’ and ‘vpython.cyvector.vector’
…could possibly mean…???
So…I’ve got this far
- using the VScode debugger I noticed BNO055 = box was type (constant) BNO055 : box, where myBoard = box and nanoBoard = box were both type (variable) myBoard : box and (variable) nanoBoard : box.
So I changed BNO055 to bnoBoard and now I have type (variable) bnoBoard : box. - From what I read about the error issue my limited understanding is that I think I’m trying to compound vector objects together that have variables of type float and this is causing issues?
- Next I changed the vector values for size and pos to integer whole numbers but the error still remains and kills the process at myObj = compound([myBoard, bnoBoard,nanoBoard])
Looking for anymore help, advice, tips, guidance on this issue as I really need to get this working
The object of the code is to rotate the boxes and arrows together, leaving the fixed axis arrows in place. If I comment out the ‘compound’ function I get the arrows rotating but not the boxes??
Here is my present code:
from vpython import *
from time import *
from math import *
import numpy as np
scene.range=5
toRad=2*np.pi/360
toDeg=1/toRad
scene.forward=vector(-1,-1,-1)
scene.width=600
scene.height=600
myArrowX = arrow(axis=vector(1,0,0), size=vector(2,0,0), shaftwidth=0.1, color=color.red)
myArrowY = arrow(axis=vector(0,1,0), size=vector(2,0,0), shaftwidth=0.1, color=color.green)
myArrowZ = arrow(axis=vector(0,0,1), size=vector(2,0,0), shaftwidth=0.1, color=color.blue)
#size = vector(length, height, width)
myBoard = box (size=vector(6,1,2), pos=vector(0,0,0), opacity = 0.5)
#myBoard = box (size=vector(6,0.2,2), pos=vector(0,0,0), opacity = 0.5)
bnoBoard = box (size=vector(1,1,1), pos=vector(2,1,0), opacity = 0.8, color=color.blue)
#bnoBoard = box (size=vector(1,0.15,0.8), pos=vector(2,0.175,0), opacity = 0.8, color=color.blue)
#BNO055 = box (size=vector(1,0.15,0.8), pos=vector(2,0.175,0), opacity = 0.8, color=color.blue)
nanoBoard = box (size=vector(2,1,1), pos=vector(-2,1,0), opacity = 0.8, color=color.green)
#nanoBoard = box (size=vector(2,0.15,0.6), pos=vector(-2,0.175,0), opacity = 0.8, color=color.green)
frontArrow=arrow(axis=vector(1,0,0), size=vector(4,0,0), shaftwidth=0.1, color=color.white, round=True)
upArrow=arrow(axis=vector(0,1,0), size=vector(4,0,0), shaftwidth=0.1, color=color.magenta, round=True)
sideArrow=arrow(axis=vector(0,0,1), size=vector(4,0,0), shaftwidth=0.1, color=color.orange, round=True)
myObj = compound([myBoard,bnoBoard,nanoBoard])
while (True):
pitch=15*toRad
for yaw in np.arange(0, 2*np.pi, .01):
rate(40)
y=vector(0,1,0)
# x=cos(psi)cos(theta) y=1sin(theta) z=sin(psi)cos(theta)
#yaw is angle psi, pitch is angle theta
k=vector(cos(yaw)*cos(pitch), sin(pitch), sin(yaw)*cos(pitch))
s=cross(k,y) #cross product k vector with y vector
v=cross(s,k) #cross product s vector with k vector
frontArrow.axis=k
sideArrow.axis=s
upArrow.axis=v
#took me a while to work this out from the lesson example on changing the arrow length
frontArrow.size=vector(4,0,0)
sideArrow.size=vector(2,0,0)
upArrow.size=vector(2,0,0)
myObj.axis=k
myObj.up=v