How to use the zencad.assemble function in zencad

To help you get started, we’ve selected a few zencad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mirmik / zencad / zencad / libs / bullet.py View on Github external
tr = (translate(*info_node[0]) * rot 
				* self.link_inertia_frame[i].rotation().to_transformation().inverse() 
				* translate(vector3(self.link_inertia_frame[i].translation())).inverse()
				)
				
				tr = translate(tr.translation() * self.simulation.scale_factor) * tr.rotation().to_transformation()
				self.link_ctr[i].relocate(tr)

		else:
			def set_kinematic_pose(u):
				if isinstance(u, zencad.assemble.kinematic_unit):
					info = p.getJointState(u.pybullet_base.boxId, u.simulation_hint2)
					pose=info[0]
					u.set_coord(pose + u.simulation_start_pose)
			zencad.assemble.for_each_unit(self.base_interactive, set_kinematic_pose)

			self.base_interactive.location_update()
github mirmik / zencad / expers / ldpendulum.py View on Github external
#!/usr/bin/env python3

import zencad
from zencad import *
import time
import zencad.libs.lagrange as lagrange
import zencad.libs.forces as forces
import zencad.libs.inertia as inertia
from zencad.libs.screw import screw
import zencad.mbody.kinematic as kinematic

L = 100
arot = kinematic.rotator(name="AROT",ax=(1,0,0))
brot = kinematic.rotator(name="BROT",ax=(1,0,0))
a = zencad.assemble.unit(name="A")
b = zencad.assemble.unit(name="B")
ma = zencad.assemble.unit(name="MA")
mb = zencad.assemble.unit(name="MB")

a.add_shape(cylinder(r=5, h=L))
b.add_shape(cylinder(r=5, h=L))

arot.link(a)
a.link(brot)
brot.link(b)

brot.relocate(up(L))

arot.set_coord(deg(90))

a.link(ma)
github mirmik / zencad / expers / rigidity0.py View on Github external
Jz = 1

		r=5

		self.con = moveX(h)
		self.shp = cylinder(r, h).rotateY(deg(90))

		if last:
			rvec = vector3(ax).cross(vector3(math.pi/2,0,0))
			print(rvec)
			nrvec = numpy.linalg.norm(rvec)
			self.shp2 = cylinder(r=5, h=20, center=True).rotateY(deg(90)).rotate(rvec/nrvec, nrvec).moveX(h)
			self.add_shape(self.shp2)
		
		self.add_shape(self.shp)
		self.connector = zencad.assemble.unit(parent=self, location=self.con)
		self.connector.add_triedron(width=2, arrlen=7, length=20)

		self.flexibility_model = zencad.libs.rigidity.rod_flexibility_matrix(E, G, F, Jx, Jy, Jz, h)
#		self.rigidity_model = zencad.libs.rigidity.rod_finite_element_model(E, G, F, Jx, Jy, Jz, h)
github mirmik / zencad / expers / ldpendulum.py View on Github external
#!/usr/bin/env python3

import zencad
from zencad import *
import time
import zencad.libs.lagrange as lagrange
import zencad.libs.forces as forces
import zencad.libs.inertia as inertia
from zencad.libs.screw import screw
import zencad.mbody.kinematic as kinematic

L = 100
arot = kinematic.rotator(name="AROT",ax=(1,0,0))
brot = kinematic.rotator(name="BROT",ax=(1,0,0))
a = zencad.assemble.unit(name="A")
b = zencad.assemble.unit(name="B")
ma = zencad.assemble.unit(name="MA")
mb = zencad.assemble.unit(name="MB")

a.add_shape(cylinder(r=5, h=L))
b.add_shape(cylinder(r=5, h=L))

arot.link(a)
a.link(brot)
brot.link(b)

brot.relocate(up(L))

arot.set_coord(deg(90))

a.link(ma)
b.link(mb)
github mirmik / zencad / zencad / libs / HIDE / physics.py View on Github external
import zencad.libs.inertia
import pyservoce

#class force_source:
#	def __init__(self, finit=screw()):
#		self.force = finit
#
#	def evaluate(self):
#		raise NotImplementedError
#
#	def attach(self, unit):
#		if not hasattr(unit, "force_sources"):
#			unit.force_sources = []
#		unit.force_sources.append(self)

class physunit(zencad.assemble.unit):
	def __init__(self, 
			parent=None, 
			location=zencad.transform.nulltrans(), 
			inertia=zencad.libs.inertia.inertia()):
		super().__init__(parent, location)
		self.inertia = inertia
		self.force_srcs = []		
		self.cm_absframe_speed = screw()
		self.cm_absframe_accel = screw()

#	def restore_kinchain_spdacc(self):
#		w = vector3()
#		for kinframe in self.kinematic_chains.kinframes:
#			w += kinframe.absframe_angular_speed()
#		self.korriolis = 
#			self.mass * self.cm_absframe_speed.lin.cross(w) * 2
github mirmik / zencad / expers / cow.py View on Github external
import numpy
import time

import zencad.malgo
from zencad import *
import zencad.assemble
from zencad.libs.screw import screw
from zencad.libs.inertia import inertia

#m = box(3)
model = (box(20,10,10,center=True)+
			box(20,10,10,center=True).rotateZ(deg(90))+
			box(20,10,10,center=True).rotateY(deg(90))
)

class cow(zencad.assemble.unit):
	r = 10

	class force_producer(zencad.assemble.unit):
		def __init__(self, parent, location):
			super().__init__(parent=parent, location=location)
			self.add_shape(cylinder(r=1,h=3,center=True))
			self.marshal = vector3(0,0,1)
			self.signal = 0

		def set_control_signal(self, signal):
			self.signal = signal

		def get_force_screw(self):
			return screw(lin=self.marshal * self.signal, ang=(0,0,0))

		def sensivity(self):
github mirmik / zencad / expers / defiler.py View on Github external
#!/usr/bin/env python3

import time
from zencad import *
import zencad.assemble
import zencad.malgo
import zencad.libs.kinematic
from zencad.libs.screw import screw

class defiler(zencad.assemble.unit):
	x = 50
	y = 20
	z = 10

	class arm(zencad.assemble.unit):
		class arm_node(zencad.assemble.unit):
			h=20
			r=1

			def __init__(self, ax=(0,1,0)):
				super().__init__()
				self.add_shape(cylinder(r=self.r, h=self.h))
				self.rot=zencad.libs.kinematic.rotator(ax=ax, location=up(self.h))
				self.link(self.rot)

		def __init__(self):
			super().__init__()
			self.arm_node_0 = self.arm_node(ax=(1,0,0))
			self.arm_node_1 = self.arm_node(ax=(1,0,0))
			#self.arm_node_2 = self.arm_node(ax=(0,1,0))
			#self.arm_node_3 = self.arm_node(ax=(1,0,0))
			#self.arm_node_4 = self.arm_node(ax=(0,1,0))
github mirmik / zencad / expers / cow.py View on Github external
self.signal = 0

		def set_control_signal(self, signal):
			self.signal = signal

		def get_force_screw(self):
			return screw(lin=self.marshal * self.signal, ang=(0,0,0))

		def sensivity(self):
			return screw(lin=self.marshal, ang=(0,0,0))

		def serve(self, delta):
			pass


	class torque_producer(zencad.assemble.unit):
		def __init__(self, parent, location):
			super().__init__(parent=parent, location=location)
			self.add_shape(cylinder(r=1,h=3))
			self.marshal = vector3(0,0,1)
			self.signal = 0

		def set_control_signal(self, signal):
			self.signal = signal

		def get_force_screw(self):
			return screw(ang=self.marshal * self.signal, lin=(0,0,0))

		def sensivity(self):
			return screw(ang=self.marshal, lin=(0,0,0))

		def serve(self, delta):
github mirmik / zencad / zencad / examples / 4.Assemble / manual-control-2.py View on Github external
CTRWIDGET = None
SLDS = None

XSLD = None
YSLD = None
ZSLD = None

class Slider(QSlider):
	def __init__(self):
		super().__init__(Qt.Horizontal)
		self.setRange(-5000,5000)
		self.setValue(0)
		self.setSingleStep(1)


class link(zencad.assemble.unit):
	def __init__(self, h=40, axis=(0,1,0)):
		super().__init__()
		if axis != (0,0,1):
			self.add_shape(cylinder(5,h) + cylinder(6,10,center=True).transform(up(h) * short_rotate((0,0,1), axis)))
		else:
			self.add_shape(cylinder(5,h))	
		self.rotator = zencad.assemble.rotator(parent=self, axis=axis, location=up(h))

r = zencad.assemble.rotator(axis=(0,0,1))
a = link(axis=(0,1,0))
b = link(axis=(1,0,0))
c = link(axis=(0,1,0))
d = link(axis=(1,0,0))
e = link(axis=(0,1,0))

r.link(a)
github mirmik / zencad / zencad / libs / bullet.py View on Github external
self.parent_index = parent_index

		ubody = u.union_shape()
		if ubody.is_nullshape() and len(u.childs) == 0:
			raise Exception("kintranslator: finite node cannot be nullshape")

		tasks.append(t(u, ubody, u.location, pjoint, paxis, parent_index))
		current_index = len(tasks)

		u.current_index = current_index

		for c in u.childs:
			pjoint=p.JOINT_FIXED
			paxis=(0,0,0)

			if isinstance(u, zencad.assemble.rotator):
				pjoint=p.JOINT_REVOLUTE
				paxis=vector3(u.axis) #u.location(vector3(u.axis))

			index = self._bind_assemble_tasks(c, tasks, current_index, 
				pjoint=pjoint, paxis=paxis,
				root=root)

			if isinstance(u, zencad.assemble.rotator):
				u.simulation_hint = index

		return current_index