How to control positioning of a faces object with the axis data of the frame it belongs to

22 views
Skip to first unread message

Ercan Avşar

unread,
Jul 14, 2015, 4:40:33 AM7/14/15
to vpytho...@googlegroups.com
I have been trying to figure out the way axis data of a frame works. Basically, I have a faces object inside a frame and I need to rotate it by some specified amounts and re-position somewhere else in space with a specific axial direction. 
For a simple explanation of the problem, I provide some code below. Code begins with drawing three arrows in x,y, and z directions in order to improve the interpretability of the visual outcomes. "rod" is a red cylinder object whose pos and axis attributes are controlled clearly in a straightforward manner. Then I generate a similar cylinder (yellow one) with extrusion and create_faces() functions and put it inside a frame. The confusion begins when I change f.axis and observe the outcome. For example, variations like 
f.axis = (0, 0, 10)
f.axis = (0, 10, 0)
f.axis = (10, 0, 10)
f.axis = (0, 10, 10)
f.axis = (10, 10, 10)
do not work in the way it works for a cylinder object. It is probably related with "world space" and "frame space" coordinates mentioned in documentation page for faces. Since cylinder is an axisymmetric object, I also added a notch to the yellow cylinder to help me understand, but I could not understand it somehow.
Any explanations about the relation between changes of f.axis and visual outcomes are appreciated. 

Also, I need to put my faces object in the space to a specified position and along a specified direction keeping its length fixed. For example, let the new position of the cylinder be (1,1,0) and its axis be (6.7735,6.7735,5.7735). This can easily be done for the red cylinder with the following codes:

rod.pos = (1,1,0)

rod.axis = (6.7735,6.7735,5.7735)

How can I get the same positioning for the yellow cylinder?



from visual import *


scene.autocenter = True

arrow(pos = vector(0,0,0), axis = vector(2,0,0), color = color.red) # x-axis

arrow(pos = vector(0,0,0), axis = vector(0,2,0), color = color.green) # y-axis

arrow(pos = vector(0,0,0), axis = vector(0,0,2), color = color.blue) # z-axis


rod = cylinder(pos=(0,0,0), axis=(0,0,10), radius=1, color = color.red) # generate red cylinder


f = frame()

my_circle1 = shapes.circle(pos=(0,0), radius=1)

my_circle2 = shapes.circle(pos=(0.9,0), radius=0.2)

extr_cylinder = extrusion(pos=[(0,3,0),(0,3,10)], shape=my_circle1 + my_circle2, color=color.yellow)

faces_cylinder = extr_cylinder.create_faces() # generate faces object

faces_cylinder.frame = f # put the faces object into the frame


## change axis of frame

f.axis = (0,10, 0)


## change position of red cylinder

#rod.pos = (1,1,0)

#rod.axis = (6.7735,6.7735,5.7735)

Ercan Avşar

unread,
Jul 14, 2015, 5:17:43 AM7/14/15
to vpytho...@googlegroups.com
I think I made a mistake in my post. rod axis should be rod.axis = (5.7735,5.7735,5.7735)  NOT (6.7735,6.7735,5.7735) 

Bruce Sherwood

unread,
Jul 14, 2015, 1:02:40 PM7/14/15
to vpytho...@googlegroups.com
Your example works correctly. The frame's position by default is (0,0,0) and its axis by default is (1,0,0). The yellow faces object is initially at (0,3,0). When you execute f.axis = (0,10,0), you rotate the frame by 90 degrees about location (0,0,0), so the yellow object also rotates by 90 degrees about location (0,0,0).

I'm not sure, but maybe what you want is to create the frame like this: f = frame(pos=(0,3,0)), so that it's simpler to think about moving or rotating the object.
Reply all
Reply to author
Forward
0 new messages