Impossible to update curve points

31 views
Skip to first unread message

Gilles Dubois

unread,
Jul 19, 2025, 6:17:12 AMJul 19
to VPython-users
from vpython import *

O=vec(0,0,0)
A=vec(1,0,0)
B=vec(0,1,0)
C=vec(0,0,1)
L=curve(pos=[A,B])
L.pos=[A,C]

gives error :
  File "/home/gilles/PycharmProjects/3Dvision/test_bug.py", line 8, in <module>
    L.pos=[A,C]
    ^^^^^
  File "/home/gilles/PycharmProjects/3Dvision/.venv/lib/python3.12/site-packages/vpython/vpython.py", line 2050, in pos
    raise AttributeError('use object methods to change its shape')
AttributeError: use object methods to change its shape

How to overcome this situation ?  Apparently it exists a method to change this attribute, but nothing on doc. Second point I changed the pos of a lot of objects without any problem. So what happens with curve ? By the way the name 'pos' is not very well chosen because actually it's a list of positions not a position.

Gilles Dubois

unread,
Jul 19, 2025, 6:28:22 AMJul 19
to VPython-users
Grok gave me the answer:
O=vec(0,0,0)
A=vec(1,0,0)
B=vec(0,1,0)
C=vec(0,0,1)
L=curve(pos=[A,B])
L.modify(1,pos=C)

Gilles Dubois

unread,
Jul 19, 2025, 6:29:26 AMJul 19
to VPython-users
Would be good to mention this in the doc

Gilles Dubois

unread,
Jul 19, 2025, 6:50:57 AMJul 19
to VPython-users
I was a little too much optimistic. I have an update function which must modify global objects among them curves, the modify .. solution, which works in the simple example, doesn't work in my example. No error no result (curves are not modified) ?????

John

unread,
Jul 19, 2025, 6:59:46 AMJul 19
to VPython-users
Here is the VPython documentation for curve.

https://glowscript.org/docs/VPythonDocs/curve.html

It mentions the modify() method in the section "Advanced Methods for Modifying Curves" and says this about it

  • modify() mycurve.modify(N, pos=mypos, color=mycolor, radius=myradius, visible=True) alters the Nth point (the starting point is N=0).

Gilles Dubois

unread,
Jul 19, 2025, 7:11:50 AMJul 19
to vpytho...@googlegroups.com
Thanks again John, I missed this additional information. But it remains that it doesn't operate in my updating function of global curves without any error message. 

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vpython-users/6bb5f9bc-4d0c-4f46-aacf-89e1412e875fn%40googlegroups.com.

John

unread,
Jul 19, 2025, 7:31:04 AMJul 19
to VPython-users
Here is a video tutorial online about advanced curves in vpython which you might find helpful.

https://youtu.be/SZ0w9gmXv-4?si=FbfW6DbaBhQRx5Od

and here is a second video about curve basic functionality in vpython

Gilles Dubois

unread,
Jul 19, 2025, 9:35:08 AMJul 19
to VPython-users
Thanks again for the links. I already read a lot about curves and their use, and by the way I used them already in three of my first programs about conic sections, paraboloids and hyperboloids, without any problem. But here my question is very simple. The fact that 'modify' works or doesn't work seems to have something to do with the scope of the variable.
Furthermore when I see the list of available possible manipulations of the list of positions, I wonder why the author didn't use the various powerful functions of standard Python  list manipulations together with the possibility of changing the pos parameter as a whole like for other 3D objects.
It would be simpler and more coherent together. Seeing all this special methods give the impression of reinventing the wheel and complicating the API for nothing

John

unread,
Jul 19, 2025, 9:35:29 AMJul 19
to VPython-users
Here is a variant of the code from the advanced curves tutorial where I modify a section of the curve.

Gilles Dubois

unread,
Jul 19, 2025, 11:24:12 AMJul 19
to VPython-users
I solved my problem (quick and dirty) by using clear() and rebuilding the curve from scratch immediately after. I don't like it but it works.

Gilles Dubois

unread,
Jul 19, 2025, 11:26:48 AMJul 19
to VPython-users
Finally my test program works with web vpython (WASM variant only) Trinket and other give error: 'A pos of a curve object must be a vector '
whih is definitely false it's a list of vectors .

Reply all
Reply to author
Forward
0 new messages