How to use the zencad.assemble.unit 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 / expers / finite.py View on Github external
class rod:
	def __init__(self, l, N):
		self.els = []
		for i in range(N):
			a = finite_element(l/N)
			if i != 0:
				self.els[-1].connector.link(a)
			self.els.append(a)

		self.rotator = zencad.cynematic.rotator(parent=self.els[-1].connector, ax=(0,1,0))

		self.input = self.els[0]
		self.output = self.rotator

class mass(zencad.assemble.unit):
	def __init__(self):
		super().__init__()
		self.set_shape(box(12, center=True))
		self.force_model = zencad.libs.rigidity.force_model_mass_point(self, 20, vec=(-1,0,1))

r0 = rod(200, 20)
mass = mass()
r0.output.link(mass)

base = zencad.assemble.unit()
base.link(r0.input)

base.relocate(rotateZ(deg(90)))
base.location_update()
github mirmik / zencad / expers / pendulum.py View on Github external
from zencad import *
import time
import zencad.libs.treedy as treedy
import zencad.libs.forces as forces
import zencad.libs.inertia as inertia
from zencad.libs.screw import screw
import zencad.mbody.kinematic as kinematic

import numpy

numpy.set_printoptions(precision=5, linewidth=200)
numpy.set_printoptions(suppress=True)
#numpy.set_printoptions(precision=1, linewidth=160)

L = 100
base = zencad.assemble.unit()
arot = kinematic.rotator(name="AROT",ax=(1,0,0))
a = zencad.assemble.unit(name="A")
ma = zencad.assemble.unit(name="MA", shape=sphere(10))

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

base.relocate(rotateY(deg(90)))
base.link(arot)
arot.link(a)
a.link(ma)

a.link(ma)
ma.relocate(up(L))

inertia.attach_inertia(ma, mass=1, Ix=1, Iy=1, Iz=1)
github mirmik / zencad / expers / treedy.py View on Github external
import cProfile
import numpy
import zencad
from zencad import *
import time
import zencad.libs.treedy as treedy
import zencad.libs.forces as forces
from zencad.libs.screw import screw
import zencad.mbody.kinematic as kinematic
import zencad.libs.inertia as inertia

L = 100
rot = kinematic.rotator(name="RBODY",ax=(0,0,1))
body = zencad.assemble.unit(name="N", shape=sphere(20))
a = zencad.assemble.unit(name="A")
b = zencad.assemble.unit(name="B")
aa = zencad.assemble.unit(name="AA")
bb = zencad.assemble.unit(name="BB")
aaa = zencad.assemble.unit(name="AAA")
bbb = zencad.assemble.unit(name="BBB")
aaaa = zencad.assemble.unit(name="AAAA")
bbbb = zencad.assemble.unit(name="BBBB")
aaaaa = zencad.assemble.unit(name="AAAAA")
bbbbb = zencad.assemble.unit(name="BBBBB")

a.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)), color=zencad.color.blue)
b.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)))
aa.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)), color=zencad.color.blue)
bb.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)))
aaa.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)), color=zencad.color.blue)
bbb.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)))
aaaa.add_shape((cylinder(h=L, r=5)+sphere(10).up(L)), color=zencad.color.blue)
github mirmik / zencad / expers / rigidity2.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 / zencad / examples / 3.Animation / pacman.py View on Github external
def __init__(self):
		super().__init__()
		self.rot0 = zencad.assemble.rotator(axis=(0,1,0), parent=self)
		self.rot1 = zencad.assemble.rotator(axis=(0,1,0), parent=self)

		self.part0 = zencad.assemble.unit()
		self.part1 = zencad.assemble.unit()

		angle = deg(180)
		upper = (sphere(r=30, yaw=angle)
			- sphere(r=10).move(-25, 20, 15)
			- sphere(r=10).move(-25, 20, -15)
		) 
		self.part0.add_shape(upper.rotateZ(0).rotateX(deg(90)), color.yellow)
		self.part0.add_shape(sphere(3).move(-20,12,15), color.green)
		self.part0.add_shape(sphere(3).move(-20,-12,15), color.blue)
		self.part1.add_shape(sphere(r=30, yaw=angle).rotateZ(-angle).rotateX(deg(90)), color.yellow)

		self.rot0.link(self.part0)
		self.rot1.link(self.part1)
github mirmik / zencad / zencad / examples / 3.Animation / pacman.py View on Github external
def __init__(self):
		super().__init__()
		self.rot0 = zencad.assemble.rotator(axis=(0,1,0), parent=self)
		self.rot1 = zencad.assemble.rotator(axis=(0,1,0), parent=self)

		self.part0 = zencad.assemble.unit()
		self.part1 = zencad.assemble.unit()

		angle = deg(180)
		upper = (sphere(r=30, yaw=angle)
			- sphere(r=10).move(-25, 20, 15)
			- sphere(r=10).move(-25, 20, -15)
		) 
		self.part0.add_shape(upper.rotateZ(0).rotateX(deg(90)), color.yellow)
		self.part0.add_shape(sphere(3).move(-20,12,15), color.green)
		self.part0.add_shape(sphere(3).move(-20,-12,15), color.blue)
		self.part1.add_shape(sphere(r=30, yaw=angle).rotateZ(-angle).rotateX(deg(90)), color.yellow)

		self.rot0.link(self.part0)
		self.rot1.link(self.part1)
github mirmik / zencad / zencad / examples / MiniGames / tennis.py View on Github external
def __init__(self):
		super().__init__(Qt.Horizontal)
		self.setRange(-5000,5000)
		self.setValue(0)
		self.setSingleStep(1)

	_value = QSlider.value
	def value(self):
		return self._value(self) / 10000 * (BOX_WIDTH-80)

class player(zencad.assemble.unit):
	def __init__(self):
		super().__init__()
		self.add_shape(box(80,10,10,center=True))

class ball(zencad.assemble.unit):
	def __init__(self):
		super().__init__()
		self.add_shape(sphere(5))

player_one = player()
player_two = player()
ball = ball()

BOX = box(BOX_WIDTH+T*2, BOX_LENGTH+T*2+PLAYER_OFF*2, 20, center=True) - box(BOX_WIDTH, BOX_LENGTH+PLAYER_OFF*2, 20, center=True)

disp(player_one)
disp(player_two)
disp(ball)
disp(BOX)

def change_angle():
github mirmik / zencad / zencad / examples / MiniGames / tennis.py View on Github external
BOX_LENGTH = 500
PLAYER_OFF = 40
T=10

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

	_value = QSlider.value
	def value(self):
		return self._value(self) / 10000 * (BOX_WIDTH-80)

class player(zencad.assemble.unit):
	def __init__(self):
		super().__init__()
		self.add_shape(box(80,10,10,center=True))

class ball(zencad.assemble.unit):
	def __init__(self):
		super().__init__()
		self.add_shape(sphere(5))

player_one = player()
player_two = player()
ball = ball()

BOX = box(BOX_WIDTH+T*2, BOX_LENGTH+T*2+PLAYER_OFF*2, 20, center=True) - box(BOX_WIDTH, BOX_LENGTH+PLAYER_OFF*2, 20, center=True)

disp(player_one)
github mirmik / zencad / zencad / examples / 4.Assemble / manual-control.py View on Github external
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

CTRWIDGET = None
SLDS = None

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


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

a = link(axis=(0,1,0))
b = link(axis=(1,0,0))
c = link(axis=(0,1,0))
d = link(axis=(1,0,0))

a.rotator.link(b)
b.rotator.link(c)
c.rotator.link(d)
d.rotator.output.add_shape(cone(5,12,40).up(10) + cylinder(5,10))

LINKS = [a,b,c,d]