def test_frame(self): # Given s = visual.sphere() a = visual.arrow() f = visual.frame(s, a) # Then axis = (1.0, 0, 0) assert_allclose(s.axis, axis, rtol=0, atol=1e-15) assert_allclose(a.axis, axis, rtol=0, atol=1e-15) assert_allclose(f.axis, axis, rtol=0, atol=1e-15) # When axis = (0, 1.0, 0.0) f.axis = axis # Then assert_allclose(s.axis, axis, rtol=0, atol=1e-15) assert_allclose(a.axis, axis, rtol=0, atol=1e-15) assert_allclose(f.axis, axis, rtol=0, atol=1e-15) # When pos = (1., 1.0, 1.0) f.pos = pos # Then assert_allclose(s.pos, pos, rtol=0, atol=1e-15) assert_allclose(a.pos, pos, rtol=0, atol=1e-15) assert_allclose(f.pos, pos, rtol=0, atol=1e-15)
def Arrow_From_A_to_B(x1, y1, z1, x2, y2, z2): ar1=visual.arrow(x=x1, y=y1, z=z1) ar1.length_cone=0.4 arrow_length=np.sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2) ar1.actor.scale=[arrow_length, arrow_length, arrow_length] ar1.pos = ar1.pos/arrow_length ar1.axis = [x2-x1, y2-y1, z2-z1] return ar1
def ArrowAB(x1, y1, z1, x2, y2, z2, Scale=1): ar1 = visual.arrow(x=x1, y=y1, z=z1) ar1.length_cone = 0.2 * Scale arrow_length = np.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) ar1.actor.scale = [ arrow_length * Scale, arrow_length * Scale, arrow_length * Scale ] ar1.pos = ar1.pos / arrow_length ar1.axis = [x2 - x1, y2 - y1, z2 - z1]
def Arrow_From_A_to_B(x1, y1, z1, x2, y2, z2): ar1 = visual.arrow(x=x1, y=y1, z=z1) ar1.length_cone = 0.4 arrow_length = np.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) ar1.actor.scale = [arrow_length, arrow_length, arrow_length] ar1.pos = ar1.pos / arrow_length ar1.axis = [x2 - x1, y2 - y1, z2 - z1] #ix = mlab.points3d(2,0,0,mode='arrow') PLUS ELEGANT ??? #http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html ! POINTS3D ! return ar1
def Arrow_From_A_to_B(x1, y1, z1, x2, y2, z2, color=(1, 1, 1)): ar1 = visual.arrow(x=x1, y=y1, z=z1) arrow_length = np.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) ar1.length_cone = 0.4 / arrow_length ar1.radius_shaft = 0.03 / arrow_length ar1.radius_cone = 0.1 / arrow_length ar1.actor.scale = [arrow_length, arrow_length, arrow_length] ar1.pos = ar1.pos / arrow_length ar1.axis = [x2 - x1, y2 - y1, z2 - z1] ar1.color = color return ar1
def test_arrow(self): # Given a = visual.arrow() # Then self.assertEqual(a.radius_cone, 0.08) self.assertEqual(a.radius_shaft, 0.03) self.assertEqual(a.length_cone, 0.35) bounds = get_bounds((0.5, 0.0, 0.0), (1.0, 0.16, 0.14)) assert_allclose(a.polydata.bounds, bounds, atol=1e-3, rtol=0) # When a.axis = 0, 0, 1 # Then bounds = get_bounds((0.0, 0.0, 0.5), (0.14, 0.16, 1.0)) assert_allclose(a.polydata.bounds, bounds, atol=1e-3, rtol=0) # Given a = visual.arrow(pos=(1.0, 1.0, 1.0)) # Then bounds = get_bounds((1.5, 1.0, 1.0), (1.0, 0.16, 0.14)) assert_allclose(a.pos, (1., 1., 1.)) assert_allclose(a.polydata.bounds, bounds, atol=1e-3, rtol=0)
def ArrowAVec(Origin, Vec, Scale=0.5, Color=WHITE, ScaleTube=1.0): Vec = np.asarray(Vec) ar1 = visual.arrow(x=Origin[0], y=Origin[1], z=Origin[2], color=Color) ar1.length_cone = min(1, 0.35 / Scale * ScaleTube) ar1.actor.scale = np.array([1, 1, 1]) * Scale ar1.radius_shaft = 0.02 / Scale * ScaleTube ar1.radius_cone = 2.5 * ar1.radius_shaft ar1.pos = np.asarray(Origin) / Scale ar1.axis = Vec
def Arrow3D(x1, y1, z1, x2, y2, z2, color=(.5, .5, .5), length_cone=.1, radius_cone=.02, radius_shaft=.01): from tvtk.tools import visual arrow = visual.arrow(x=x1, y=y1, z=z1, color=color) arrow.length_cone = length_cone arrow.radius_cone = radius_cone arrow.radius_shaft = radius_shaft arrow_length = np.sqrt((x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2) arrow.actor.scale = [arrow_length, arrow_length, arrow_length] arrow.pos = arrow.pos / arrow_length arrow.axis = [x2 - x1, y2 - y1, z2 - z1] return arrow
box (pos = (xx,yy,zz), length=x, height=y, width=z, color=(red,green,blue)) def wirecube(s): c = curve(color = (1,1,1), radius=1) pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size = (side,side,side), representation = 'w' ) i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0)) ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3) disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5) xx = arange(0,4*pi,pi/10.) spring=curve(color=(1,.7,.1), radius=0.4) for y in xx: spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30]) show()
pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s), (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s), (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s), (s, -s, -s)] for pt in pts: c.append(pt) side = 150.0 cube = box(size=(side, side, side), representation='w') i = 0 while i < 100: random_box() i = i + 1 arrow(axis=(0, 12, 0), radius_shaft=3.5, color=(1, 0, 0)) ball = sphere(pos=(-side / 2., -side / 2., -side / 2.), color=(1, 1, 0), radius=3) disk = cylinder(pos=(side / 2., side / 2., -side / 2.), color=(.3, .3, 1), axis=(1, 1, 0), radius=5) xx = arange(0, 4 * pi, pi / 10.) spring = curve(color=(1, .7, .1), radius=0.4) for y in xx: spring.append([20 + cos(2 * y), y / 2. - 30, -20 + sin(2 * y) + 30]) show()
def func_init_wind_vane(self): # draw an arrow as a wind vane, at the original point self.wind_vane = visual.arrow(pos=(0, 0, 0)) self.func_change_wind_vane(self.mean_wind_vector)