Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_import_object(self):
# Update Scene
scene = canvas.GraphicsCanvas3D(title="Test Import Object")
scene.grid_visibility(False)
# Check num objects
num_obj = len(scene.scene.objects)
# Import an object
graphic_obj = stl.import_object_from_numpy_stl(
'./roboticstoolbox/models/meshes/UNIMATE/puma560/link0.stl',
scene.scene
)
# Verify object was added
self.assertEqual(graphic_obj.pos, vector(0, 0, 0)) # Object is at origin
# Can't check how many objects, as each triangle counts as one. No way to know correct amount
ref_vel = self.ref_vel
pos = np.array([state[0], state[1], state[2]]).flatten()
att = np.array([state[3], state[4], state[5], state[6]]).flatten()
vel = np.array([state[7], state[8], state[9]]).flatten()
load_pos = np.array([state[10], state[11], state[12]]).flatten()
load_vel = np.array([state[13], state[14], state[15]]).flatten()
current_quat = Quaternion(att)
x_axis = current_quat.rotation_matrix.dot(np.array([1.0, 0.0, 0.0]))
y_axis = current_quat.rotation_matrix.dot(np.array([0.0, 1.0, 0.0]))
z_axis = current_quat.rotation_matrix.dot(np.array([0.0, 0.0, 1.0]))
tether_vec = load_pos - pos
if self.viewer is None:
self.viewer = canvas(title='Quadrotor 3D Slungload', width=640, height=480, center=vector(0, 0, 0), forward=vector(1, 1, -1), up=vector(0, 0, 1), background=color.white)
self.render_quad1 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(x_axis[0],x_axis[1],x_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_quad2 = box(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(y_axis[0],y_axis[1],y_axis[2]), length=0.2, height=0.05, width=0.05)
self.render_rotor1 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor2 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor3 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_rotor4 = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(0.01*z_axis[0],0.01*z_axis[1],0.01*z_axis[2]), radius=0.2, color=color.cyan, opacity=0.5)
self.render_velocity = pointer = arrow(pos=vector(pos[0],pos[1],0), axis=vector(vel[0],vel[1],vel[2]), shaftwidth=0.05, color=color.green)
self.render_ref = sphere(canvas = self.viewer, pos=vector(ref_pos[0], ref_pos[1], ref_pos[2]), radius=0.02, color=color.blue, make_trail = True)
self.render_tether = cylinder(canvas = self.viewer, pos=vector(pos[0],pos[1],0), axis=vector(tether_vec[0],tether_vec[1],tether_vec[2]), radius=0.01, color=color.black)
self.render_load = sphere(canvas = self.viewer, pos=vector(load_pos[0], load_pos[1], load_pos[2]), radius=0.1, color=color.red, make_trail = True)
if self.state is None: return None
self.render_quad1.pos.x = pos[0]
self.render_quad1.pos.y = pos[1]
self.render_quad1.pos.z = pos[2]
self.render_quad2.pos.x = pos[0]
min_z_coord = z_origin + int(-(self.__num_squares / 2) + (sign(camera_axes.z) * -1) * (self.__num_squares / 2))
max_z_coord = z_origin + int((self.__num_squares / 2) + (sign(camera_axes.z) * -1) * (self.__num_squares / 2))
# XZ plane
for x_point in range(min_x_coord, max_x_coord + 1):
# Draw a line across for each x coord, along the same y-axis, from min to max z coord
xz_lines.append(create_line(
vector(x_point, y_origin, min_z_coord),
vector(x_point, y_origin, max_z_coord),
self.__scene
))
for z_point in range(min_z_coord, max_z_coord + 1):
# Draw a line across each z coord, along the same y-axis, from min to max z coord
xz_lines.append(create_line(
vector(min_x_coord, y_origin, z_point),
vector(max_x_coord, y_origin, z_point),
self.__scene
))
# XY plane
for x_point in range(min_x_coord, max_x_coord + 1):
# Draw a line across each x coord, along the same z-axis, from min to max y coord
xy_lines.append(create_line(
vector(x_point, min_y_coord, z_origin),
vector(x_point, max_y_coord, z_origin),
self.__scene
))
for y_point in range(min_y_coord, max_y_coord + 1):
# Draw a line across each y coord, along the same z-axis, from min to max x coord
xy_lines.append(create_line(
vector(min_x_coord, y_point, z_origin),
vector(max_x_coord, y_point, z_origin),
def make_grid(unit, n):
nunit = unit * n
for i in range(n+1):
if i%5==0:
lcolor = vector(0.5,0.5,0.5)
else:
lcolor = vector(0.5, 0.5, 0.5)
curve(pos=[(0,i*unit,0), (nunit, i*unit, 0)],color=lcolor)
curve(pos=[(i*unit,0,0), (i*unit, nunit, 0)],color=lcolor)
curve(pos=[(0,-i*unit,0), (-nunit, -i*unit, 0)],color=lcolor)
curve(pos=[(-i*unit,0,0), (-i*unit, -nunit, 0)],color=lcolor)
curve(pos=[(0,i*unit,0), (-nunit, -i*unit, 0)],color=lcolor)
curve(pos=[(i*unit,0,0), (-i*unit, -nunit, 0)],color=lcolor)
vector(max_x_coord, y_origin, z_point),
self.__scene
))
# XY plane
for x_point in range(min_x_coord, max_x_coord + 1):
# Draw a line across each x coord, along the same z-axis, from min to max y coord
xy_lines.append(create_line(
vector(x_point, min_y_coord, z_origin),
vector(x_point, max_y_coord, z_origin),
self.__scene
))
for y_point in range(min_y_coord, max_y_coord + 1):
# Draw a line across each y coord, along the same z-axis, from min to max x coord
xy_lines.append(create_line(
vector(min_x_coord, y_point, z_origin),
vector(max_x_coord, y_point, z_origin),
self.__scene
))
# YZ plane
for y_point in range(min_y_coord, max_y_coord + 1):
# Draw a line across each y coord, along the same x-axis, from min to max z coord
yz_lines.append(create_line(
vector(x_origin, y_point, min_z_coord),
vector(x_origin, y_point, max_z_coord),
self.__scene
))
for z_point in range(min_z_coord, max_z_coord + 1):
# Draw a line across each z coord, along the same x-axis, from min to max y coord
yz_lines.append(create_line(
vector(x_origin, min_y_coord, z_point),
def draw_electrical_field(num_charge):
scene = canvas(title='electric field of a list of charges', width=800, height=600, background=color.magenta)
# dx = L / num_charge
Q = 1e-8 # total charges
# dq = 1e-8 / 6 # define charge of electrons
dq = Q / num_charge
charges = []
space_between = 2 * view_space_length / (num_charge + 1) # evenly divide space between each electrons
for x in arange(-view_space_length + space_between, view_space_length, space_between):
q = ElectricBall(pos=vector(x, 0, 0), radius=1, color=color.red, charge=dq)
charges.append(q)
# creat arrow around electric balls
arrows = []
observe_points_dis = 0.5 * view_space_length
for x in arange(-1.5 * view_space_length, 1.51 * view_space_length, observe_points_dis):
for y in arange(-1.0 * view_space_length, 1.01 * view_space_length, observe_points_dis):
for z in arange(-1.0 * view_space_length, 1.01 * view_space_length, observe_points_dis):
pointer = arrow(pos=vector(x, y, z), color=color.blue, opacity=0.0)
electrical_vector = vector(0, 0, 0)
# infinity large arrows will be ignored
infinity = False
# each arrow is affected by all of the charges
for q in charges:
self.__scene
))
# XY plane
for x_point in range(min_x_coord, max_x_coord + 1):
# Draw a line across each x coord, along the same z-axis, from min to max y coord
xy_lines.append(create_line(
vector(x_point, min_y_coord, z_origin),
vector(x_point, max_y_coord, z_origin),
self.__scene
))
for y_point in range(min_y_coord, max_y_coord + 1):
# Draw a line across each y coord, along the same z-axis, from min to max x coord
xy_lines.append(create_line(
vector(min_x_coord, y_point, z_origin),
vector(max_x_coord, y_point, z_origin),
self.__scene
))
# YZ plane
for y_point in range(min_y_coord, max_y_coord + 1):
# Draw a line across each y coord, along the same x-axis, from min to max z coord
yz_lines.append(create_line(
vector(x_origin, y_point, min_z_coord),
vector(x_origin, y_point, max_z_coord),
self.__scene
))
for z_point in range(min_z_coord, max_z_coord + 1):
# Draw a line across each z coord, along the same x-axis, from min to max y coord
yz_lines.append(create_line(
vector(x_origin, min_y_coord, z_point),
vector(x_origin, max_y_coord, z_point),
def __init__(self, color=color.red, radius=0, charge=0, pos=vector(0, 0, 0)):
sphere.__init__(self, pos=pos, radius=radius, color=color)
self.charge = charge
if camera_axes.z < 0:
self.grid_object[self.__planes_idx][self.__xy_plane_idx].pos = vector(x_middle, y_middle, min_z_coord)
else:
self.grid_object[self.__planes_idx][self.__xy_plane_idx].pos = vector(x_middle, y_middle, max_z_coord)
# XZ Plane
if camera_axes.y < 0:
self.grid_object[self.__planes_idx][self.__xz_plane_idx].pos = vector(x_middle, min_y_coord, z_middle)
else:
self.grid_object[self.__planes_idx][self.__xz_plane_idx].pos = vector(x_middle, max_y_coord, z_middle)
# YZ Plane
if camera_axes.x < 0:
self.grid_object[self.__planes_idx][self.__yz_plane_idx].pos = vector(min_x_coord, y_middle, z_middle)
else:
self.grid_object[self.__planes_idx][self.__yz_plane_idx].pos = vector(max_x_coord, y_middle, z_middle)