Groups
Groups

Trying to rotate triangles

69 views
Skip to first unread message

Gilles Dubois

unread,
Aug 3, 2025, 5:05:00 PMAug 3
to VPython-users
Here is a small program building a triangle and trying to rotate it around the x axis
from vpython import *

A,B,C=vec(-1,0,0),vec(0,sqrt(3),0),vec(1,0,0)
VA,VB,VC=vertex(pos=A),vertex(pos=B),vertex(pos=C)
T=triangle(v0=VA,v1=VB,v2=VC)
print(B)
T.rotate(axis=vec(1,0,0),angle=pi/2origin=vec(0,0,0)) #no error but does nothing
print(B) # confirmation B still on the same place
OK ! try something else :
from vpython import *

A, B, C = vec(-100), vec(0, sqrt(3), 0), vec(100)
VA, VB, VC = vertex(pos=A), vertex(pos=B), vertex(pos=C)
T = triangle(v0=VA, v1=VB, v2=VC)
print(VB.pos)
# T.rotate(axis=vec(1,0,0),angle=pi/2, origin=vec(0,0,0)) #no error but does nothing

# let's pack T into a compound with only one entry
T1 = compound([T])
# rotate the compound and watch
T1.rotate(axis=vec(100), angle=pi / 2origin=vec(000)) # according rendering does the job
# but ... only if we comment the T.rotate line
# if we uncomment this line no action at all, does it mean that the system estimates that the first rotate was successful ?
# so we can guess that finally the job is done, let's check
print(VB.pos) # strangely B is still declared at the same place, although visually T1 lies in the xOz plane ???
 This is just the beginning of the story, more to come if somebody interested.

Bruce Sherwood

unread,
Aug 6, 2025, 5:03:49 PMAug 6
to VPython-users
From the documentation for triangles:

The only way to rotate a triangle is to rotate each vertex.
Bruce 
l

Gilles Dubois

unread,
Aug 6, 2025, 5:27:03 PMAug 6
to VPython-users
Actually to pack it into a compound is working too .

Gilles Dubois

unread,
Aug 6, 2025, 5:46:18 PMAug 6
to VPython-users
Ok ! Since we can rotate vertices, let's do it. But we could expect that normals would be rotated the same. But no !
This small program proves that after rotating a vertex, the normal of this vertex is unchanged. Why ?
from vpython import *
i = vec(1, 0, 0)
j = vec(0, 1, 0)
k = vec(0, 0, 1)

# tracé de l'axe x'Ox (abscisses)
xmin = vec(-2, 0, 0)
xmax = vec(2, 0, 0)
axex = curve(pos=[xmin, xmax], color=color.blue) # segment de longueur 20

# tracé de l'axe y'Oy (ordonnées)
ymin = vec(0, -2, 0)
ymax = vec(0, 2, 0)
axey = curve(pos=[ymin, ymax], color=color.green) # même chose

# tracé de l'axe z'Oz (cotes)
zmin = vec(0, 0, -2)
zmax = vec(0, 0, 2)
axez = curve(pos=[zmin, zmax], color=color.yellow) # idem

scene.camera.rotate(angle=pi / 24, axis=k, origin=vec(0, 0, 0))
scene.range = 0.5
A=j
sphere(pos=A,radius=0.1)
VA=vertex(pos=A)
nar=arrow(axis=VA.normal,pos=A)
VA.rotate(axis=i,angle=pi/2,origin=i)
sphere(pos=VA.pos,radius=0.1)
nar2=arrow(axis=VA.normal,pos=VA.pos) #normal unchanged not modified by rotation.

Capture d’écran du 2025-08-06 23-43-43.png

Bruce Sherwood

unread,
Aug 12, 2025, 1:51:10 PMAug 12
to VPython-users
Here is an example of rotating a triangle:

v1 = vertex(pos=vec(0,1,0), normal=vec(0,0,1), color=color.red)
v2 = vertex(pos=vec(-1,0,0), normal=vec(0,0,1), color=color.green)
v3 = vertex(pos=vec(1,0,0), normal=vec(0,0,1), color=color.blue)
t = triangle(vs=[v1,v2, v3])
scene.autoscale = False
distant_light(direction=vec(1,0,0), color=color.white)
scene.pause()
v1.normal = vec(1,0,0)
v2.pos=vec(0,0,1)
v2.normal =v1.normal
v3.pos=vec(0,0,-1)
v3.normal = v1.normal

Bruce

Gilles Dubois

unread,
Aug 12, 2025, 3:05:37 PMAug 12
to vpytho...@googlegroups.com

Thank you Bruce. However I begin to understand how things work and I can manage almost all situations

--
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/a1ad3ffe-17e4-4281-a566-fd63cdd4fea5n%40googlegroups.com.

Bruce Sherwood

unread,
Aug 12, 2025, 7:38:00 PMAug 12
to VPython-users
Another approach:

v1 = vertex(pos=vec(0,1,0), normal=vec(0,0,1), color=color.red)
v2 = vertex(pos=vec(-1,0,0), normal=vec(0,0,1), color=color.green)
v3 = vertex(pos=vec(1,0,0), normal=vec(0,0,1), color=color.blue)
t = triangle(vs=[v1,v2, v3])
scene.autoscale = False
distant_light(direction=vec(1,0,0), color=color.white)
scene.pause()
v2.rotate(angle=pi/2, axis=vec(0,1,0))
v3.rotate(angle=pi/2, axis=vec(0,1,0))
Reply all
Reply to author
Forward
0 new messages
Search
Clear search
Close search
Google apps
Main menu