Skip to content

joints -- Kinematic Joints definition

Usual joints

Ball(solids, center, local=None, default=None)

Bases: Joint

Joint for rotation all around a point.

ball joint

Classical definition: Ball (point) the initial state doen't require more data the class holds a point for each side

Source code in madcad/joints.py
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
def __init__(self, solids, center, local=None, default=None):
	self.solids = solids
	local = local or center

	if default is not None:
		self.default = default

	if isinstance(center, mat4):
		self.post = center
		self.pre = affineInverse(local)
		self.position = center[3].xyz, local[3].xyz
	elif isinstance(center, vec3):
		self.post = translate(center)
		self.pre = translate(-local)
		self.position = center, local
	else:
		raise TypeError("ball can only be placed on a vec3 or mat4")
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

post = center instance-attribute

pre = affineInverse(local) instance-attribute

position = (center[3].xyz, local[3].xyz) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

bounds = (quat(-2, -2, -2, -2), quat(2, 2, 2, 2)) class-attribute instance-attribute

increment = quat(0.5, 0.5, 0.5, 0.5) class-attribute instance-attribute

default = quat() class-attribute instance-attribute

__repr__()

Source code in madcad/joints.py
516
517
def __repr__(self):
	return '{}({}, ({:.3g},{:.3g},{:.3g}))'.format(self.__class__.__name__, self.solids, *self.post[3].xyz)

normalize(orient)

Source code in madcad/joints.py
523
524
def normalize(self, orient):
	return normalize(quat(orient))

direct(orient)

Source code in madcad/joints.py
526
527
def direct(self, orient):
	return self.post * mat4(normalize(quat(orient))) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
529
530
def inverse(self, matrix, close=None):
	return quat(affineInverse(self.post) * matrix * affineInverse(self.pre))

grad(orient)

Source code in madcad/joints.py
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
def grad(self, orient):
	w,x,y,z = orient
	return (
		self.post * mat4(
			0,    2*z, -2*y, 0,
			-2*z,  0,    2*x, 0,
			2*y, -2*x,  0,   0,
			0,    0,    0,   0,
			) * self.pre,
		self.post * mat4( 
			0,   2*y,  2*z, 0,
			2*y, -4*x,  2*w, 0,
			2*z, -2*w, -4*x, 0,
			0,   0,    0,   0,
			) * self.pre,
		self.post * mat4(
			-4*y,  2*x, -2*w, 0,
			2*x,  0,    2*z, 0,
			2*w,  2*z, -4*y, 0,
			0,    0,    0,   0,
			) * self.pre,
		self.post * mat4(
			-4*z,  2*w,  2*x, 0,
			-2*w, -4*z,  2*y, 0,
			2*x,  2*y,  0,   0,
			0,    0,    0,   0,
			) * self.pre,
		)

transmit(force, parameters=None, velocity=None)

Source code in madcad/joints.py
561
562
def transmit(self, force, parameters=None, velocity=None):
	return Screw(vec3(0), force.momentum, self.center)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color

	from .primitives import ArcCentered

	size = settings.display['joint_size']
	radius = size/3
	sch = Scheme()
	resolution = ('div', 16)

	center = self.post[3].xyz
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(center), maxsize/size))
	if attach_start:
		x,y,z = dirbase(normalize(center - attach_start))
	else:
		x,y,z = mat3()
	profile = ArcCentered(Axis(O,y), x*radius, -z*radius).mesh(resolution=resolution)
	emisphere = gt.revolution(profile, Axis(O,z), resolution=resolution)
	sch.add(emisphere, shader='ghost')
	sch.add(emisphere.outlines(), shader='line')
	if attach_start:
		sch.set(shader='line')
		sch.add(-z*radius)
		sch.add(attach_start, space=world_solid(self.solids[0]))

	center = affineInverse(self.pre)[3].xyz
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(center), maxsize/size))
	sch.add(gt.icosphere(O, radius*0.8, resolution=('div', 3)), shader='ghost')
	if attach_end:
		sch.set(shader='line')
		sch.add(radius*0.8*normalize(attach_end-center))
		sch.add(attach_end, space=world_solid(self.solids[1]))

	return sch

Revolute(solids, axis, local=None, default=None, bounds=None)

Bases: Joint

Joint for revolution around an axis

revolute joint

Source code in madcad/joints.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
def __init__(self, solids, axis: Axis, local=None, default=None, bounds=None):
	self.solids = solids
	local = local or axis

	if default is not None:
		self.default = default
	if bounds is not None:
		self.bounds = bounds

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
		self.position = axis[3].xyz, local[3].xyz
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
		self.position = axis[0], local[0]
	else:
		raise TypeError('Revolute can only be placed on an Axis or a mat4')
	self.scale = max(glm.abs(self.post[3]))

bounds = (-inf, inf) class-attribute instance-attribute

default = 0 class-attribute instance-attribute

increment = 1 class-attribute instance-attribute

solids = solids instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

position = (axis[3].xyz, local[3].xyz) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

__repr__()

Source code in madcad/joints.py
70
71
72
def __repr__(self):
	return '{}({}, Axis(({:.3g},{:.3g},{:.3g}), ({:.3g},{:.3g},{:.3g})))'.format(
		self.__class__.__name__, self.solids, *self.post[3].xyz, *self.post[2].xyz)

direct(angle)

Source code in madcad/joints.py
74
75
def direct(self, angle) -> mat4:
	return self.post * rotate(angle, Z) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
77
78
79
80
81
82
83
def inverse(self, matrix, close=None):
	if close is None:
		close = 0
	m = affineInverse(self.post) * matrix * affineInverse(self.pre)
	angle = - atan2(m[1][0] - m[0][1], m[0][0] + m[1][1])
	angle += (2*pi) * ((angle + pi - close) // (2*pi))
	return angle

grad(angle, delta=1e-06)

Source code in madcad/joints.py
85
86
def grad(self, angle, delta=1e-6):
	return self.post * drotate(angle, Z) * self.pre,

transmit(force, parameters=None, velocity=None)

Source code in madcad/joints.py
88
89
90
def transmit(self, force, parameters=None, velocity=None) -> Screw:
	l = force.locate(self.axis[0])
	return Screw(l.resulting, project(l.momentum, self.axis[1]))

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color

	size = settings.display['joint_size']
	radius = size/4
	sch = Scheme()
	resolution = ('div', 16)

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size))
	cylinder = gt.cylinder(
					-z*size*0.4, 
					+z*size*0.4, 
					radius=size/4, 
					resolution=resolution,
					fill=False,
					)
	sch.add(cylinder, shader='ghost')
	sch.add(cylinder.outlines(), shader='line')
	if attach_start:
		v = normalize(noproject(attach_start - o, z))
		if not isfinite(v):
			v = x
		p = v*size/4
		sch.add(gt.cone(p+size*cornersize*v, p, size*cornersize, fill=False, resolution=('div', 4)), shader='fill')
		sch.set(shader='line')
		sch.add(p + v*size*cornersize)
		sch.add(attach_start, space=world_solid(self.solids[0]))

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size))
	c1 = primitives.Circle(
					(-z*size*0.5, -z), 
					radius, 
					resolution=resolution,
					).mesh()
	c2 = primitives.Circle(
					(+z*size*0.5, z), 
					radius, 
					resolution=resolution,
					).mesh()
	# sch.add([z*size*0.5, o+z*size*0.5], shader='line')
	sch.add(c1, shader='line')
	sch.add(c2, shader='line')
	sch.add(gt.fill(c1), shader='ghost')
	sch.add(gt.fill(c2), shader='ghost')

	if attach_end:
		sch.set(shader='line')
		side = z * size * 0.5
		if dot(attach_end-o, side) < 0:
			side = -side
		if dot(attach_end, side)**2 < length2(attach_end)*length2(side) * 0.25:
			radial = normalize(noproject(attach_end-o, z))
			sch.add(side + radial*radius)
			sch.add(side + radial*2*radius)
		else:
			sch.add(side)
		sch.add(attach_end, space=world_solid(self.solids[1]))

	return sch

Cylindrical(solids, axis, local=None, default=None, bounds=None)

Bases: Joint

Joint with rotation and translation around an axis

cylindrical joint

Source code in madcad/joints.py
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
def __init__(self, solids, axis: Axis, local=None, default=None, bounds=None):
	self.solids = solids
	local = local or axis

	if default is not None:
		self.default = default
	if bounds is not None:
		self.bounds = bounds

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
		self.position = axis[3].xyz, local[3].xyz
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
		self.position = axis[0], local[0]
	else:
		raise TypeError('Pivot can only be placed on an Axis or a mat4')
	self.scale = max(glm.abs(self.post[3]))

bounds = (vec2(-inf), vec2(inf)) class-attribute instance-attribute

increment = vec2(1, inf) class-attribute instance-attribute

default = vec2(0) class-attribute instance-attribute

solids = solids instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

position = (axis[3].xyz, local[3].xyz) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

__repr__()

Source code in madcad/joints.py
409
410
411
def __repr__(self):
	return '{}({}, Axis(({:.3g},{:.3g},{:.3g}), ({:.3g},{:.3g},{:.3g})))'.format(
		self.__class__.__name__, self.solids, *self.post[3].xyz, *self.post[2].xyz)

direct(parameters)

Source code in madcad/joints.py
413
414
def direct(self, parameters) -> mat4:
	return self.post * rotate(parameters[0], Z) * translate(parameters[1]*Z) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
416
417
418
419
420
def inverse(self, matrix, close=None):
	m = affineInverse(self.post) * mat4(matrix) * affineInverse(self.pre)
	angle = atan2(m[1][0] - m[0][1], m[0][0] + m[1][1])
	angle += (2*pi) * ((angle + pi - close) // (2*pi))
	return angle, m[2][2]

grad(parameters, delta=1e-06)

Source code in madcad/joints.py
422
423
424
425
426
def grad(self, parameters, delta=1e-6):
	return (
		self.post * drotate(parameters[0], Z) * self.pre,
		self.post * dtranslate(Z) * self.pre,
		)

transmit(force, parameters=None, velocity=None)

Source code in madcad/joints.py
428
429
430
def transmit(self, force, parameters=None, velocity=None) -> Screw:
	l = force.locate(self.axis[0])
	return Screw(l.resulting, project(l.momentum, self.axis[1]))

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color

	size = settings.display['joint_size']
	radius = size/4
	sch = Scheme()
	resolution = ('div', 16)

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size))
	cylinder = gt.cylinder(
					o-z*size*0.4, 
					o+z*size*0.4, 
					radius=size/4, 
					resolution=resolution,
					fill=False,
					)
	sch.add(cylinder, shader='ghost')
	sch.add(cylinder.outlines(), shader='line')
	if attach_start:
		v = normalize(noproject(attach_start - o, z))
		if not isfinite(v):
			v = x
		p = v*size/4
		sch.add(gt.cone(p+size*cornersize*v, p, size*cornersize, fill=False, resolution=('div', 4)), shader='fill')
		sch.set(shader='line')
		sch.add(p + v*size*cornersize)
		sch.add(attach_start, space=world_solid(self.solids[0]))

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size))
	sch.add([o-z*size*0.5, o+z*size*0.5], shader='line')

	sch.set(shader='fill')
	if attach_end:
		sch.set(shader='line')
		side = z * size * 0.5
		if dot(attach_end-o, side) < 0:
			side = -side
		if dot(attach_end, side)**2 < length2(attach_end)*length2(side) * 0.25:
			radial = normalize(noproject(attach_end-o, z))
			sch.add(side + radial*radius)
			sch.add(side + radial*2*radius)
		else:
			sch.add(side)
		sch.add(attach_end, space=world_solid(self.solids[1]))

	return sch

Prismatic(solids, axis, local=None, default=None, bounds=None)

Bases: Joint

Joint for translation only in a direction

prismatic joint

Classical definition: Prismatic (direction vector) the initial state requires more parameters: the relative placements of the solids this class holds a base for each of the solids, bases are (0,X,Y) where X,Y are constrained to keep the same direction across bases, and the bases origins lays on their common Z axis

Source code in madcad/joints.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
def __init__(self, solids, axis: Axis, local=None, default=None, bounds=None):
	self.solids = solids
	local = local or axis

	if default is not None:
		self.default = default
	if bounds is not None:
		self.bounds = bounds

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
		self.position = axis[3].xyz, local[3].xyz
	elif isinstance(axis, vec3):
		self.post = mat4(quat(Z, axis))
		self.pre = mat4(quat(local, Z))
		self.position = axis, local
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
		self.position = axis[0], local[0]
	else:
		raise TypeError('Track can only be placed on a vec3, Axis or mat4')
	self.scale = max(glm.abs(self.post[3]))

bounds = (-inf, inf) class-attribute instance-attribute

increment = inf class-attribute instance-attribute

default = 0 class-attribute instance-attribute

solids = solids instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

position = (axis[3].xyz, local[3].xyz) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

__repr__()

Source code in madcad/joints.py
305
306
307
def __repr__(self):
	return '{}({}, vec3({:.3g},{:.3g},{:.3g}))'.format(
		self.__class__.__name__, self.solids, *self.post[3].xyz)

direct(translation)

Source code in madcad/joints.py
309
310
def direct(self, translation):
	return self.post * translate(translation*Z) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
312
313
def inverse(self, matrix, close=None):
	return (affineInverse(self.post) * matrix * affineInverse(pre))[2][2]

grad(translation, delta=1e-06)

Source code in madcad/joints.py
315
316
def grad(self, translation, delta=1e-6):
	return self.post * dtranslate(Z) * self.pre

transmit(force, parameters=None, velocity=None)

Source code in madcad/joints.py
318
319
320
321
def transmit(self, force, parameters=None, velocity=None):
	z0, z1 = cross(b0[1],b0[2]), cross(b1[1],b1[2])
	normal = normalize(z0 + z1)
	return Screw(noproject(action.resulting, normal), action.momentum, action.position)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color

	size = settings.display['joint_size']
	sch = Scheme()

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size),
		)
	profile = gt.parallelogram(0.4*size*x, 0.4*size*y, origin=o, alignment=0.5, fill=False)
	profile.tracks = typedlist(range(len(profile.edges)))
	exterior = gt.extrusion(profile, size*z, alignment=0.5)
	exterior.splitgroups()
	sch.add(exterior, shader='ghost')
	sch.add(exterior.outlines(), shader='line')
	if attach_start:
		v = attach_start - o
		if abs(dot(v,x)) > abs(dot(v,y)):
			v = x if dot(v,x)>0 else -x
		else:
			v = y if dot(v,y)>0 else -y
		p = o + v*0.2*size
		sch.add(gt.cone(p+size*cornersize*v, p, size*cornersize, fill=False, resolution=('div', 4)), shader='fill')
		sch.set(shader='line')
		sch.add(p+size*cornersize*v)
		sch.add(attach_start, space=world_solid(self.solids[0]))

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size),
		)
	interior = gt.extrusion(Web([
		o-0.2*size*(x+y),
		o+0.2*size*(x+y),
		o-0.2*size*(x-y),
		o+0.2*size*(x-y),
		],
		[(0,1), (2,3)],
		), size*z, alignment=0.5)
	sch.add(interior.outlines(), shader='line')
	if attach_end:
		v = attach_end - o
		v = z if dot(v, z) > 0 else -z
		p = o + v*size/2
		sch.add(p)
		sch.add(attach_end, space=world_solid(self.solids[1]))

	return sch

Planar(solids, axis, local=None, default=None, bounds=None)

Bases: Joint

Joint for translation in 2 directions and rotation around the third direction

planar joint

Classical definition: Planar (direction vector) the initial state requires an additional distance between the solids this class holds an axis for each side, the axis origins are constrained to share the same projections on the normal

Source code in madcad/joints.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def __init__(self, solids, axis, local=None, default=None, bounds=None):
	self.solids = solids
	local = local or axis

	if default is not None:
		self.default = default
	if bounds is not None:
		self.bounds = bounds

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
		self.position = axis[3].xyz, local[3].xyz
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
		self.position = axis[0], local[0]
	else:
		raise TypeError('Planar can only be placed on an Axis or a mat4')
	self.scale = max(glm.abs(self.post[3]))

bounds = (vec3(-inf), vec3(inf)) class-attribute instance-attribute

increment = vec3(inf) class-attribute instance-attribute

default = vec3(0, 0, 0) class-attribute instance-attribute

solids = solids instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

position = (axis[3].xyz, local[3].xyz) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

__repr__()

Source code in madcad/joints.py
197
198
199
def __repr__(self):
	return '{}({}, Axis(({:.3g},{:.3g},{:.3g}), ({:.3g},{:.3g},{:.3g})))'.format(
		self.__class__.__name__, self.solids, *self.post[3].xyz, *self.post[2].xyz)

direct(position)

Source code in madcad/joints.py
201
202
def direct(self, position: tuple):
	return mat4(self.post) * translate(vec3(position.xy, 0)) * rotate(position.z, Z) * mat4(self.pre)

inverse(matrix, close=None)

Source code in madcad/joints.py
204
205
206
207
208
def inverse(self, matrix, close=None):
	m = mat4(transpose(self.post)) * matrix * mat4(transpose(self.pre))
	angle = atan2(m[0][1], m[0][0])
	angle += (2*pi) * ((angle + pi - close) // (2*pi))
	return vec3(m[3].xy, angle)

grad(position, delta=1e-06)

Source code in madcad/joints.py
210
211
212
213
214
215
def grad(self, position: vec3, delta=1e-6):
	return (
		self.post * dtranslate(X) * rotate(position.z, Z) * self.pre,
		self.post * dtranslate(Y) * rotate(position.z, Z) * self.pre,
		self.post * translate(vec3(position.xy,0)) * drotate(position.z, Z) * self.pre,
		)

transmitable(force, parameters=None, velocity=None)

Source code in madcad/joints.py
217
218
219
220
def transmitable(self, force, parameters=None, velocity=None):
	a0,a1 = solidtransform_axis(self.solids[0], self.axis[0])
	normal = normalize(a0[1] + a1[1])
	return Screw(project(action.resulting, normal), noproject(action.momentum, normal), action.position)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color

	size = settings.display['joint_size']
	sch = Scheme()
	gap = 0.1

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size),
		)
	square = gt.parallelogram(x*size, y*size, origin=o-gap*size*z, alignment=0.5)
	sch.add(square.outlines(), shader='line')
	sch.add(square, shader='ghost')

	if attach_start:
		sch.add(gt.cone(o-size*(gap+cornersize)*z, o-size*gap*z, size*cornersize, fill=False, resolution=('div', 4)), shader='fill')
		sch.set(shader='line')
		sch.add(o-size*(gap+cornersize)*z)
		sch.add(attach_start, space=world_solid(self.solids[0]))

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	sch.set(
		track = index[self.solids[1]],
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size),
		)
	square = gt.parallelogram(-x*size, y*size, origin=o+gap*size*z, alignment=0.5)
	sch.add(square.outlines(), shader='line')
	sch.add(square, shader='ghost')

	if attach_end:
		sch.add(gt.cone(o+size*(gap+cornersize)*z, o+size*gap*z, size*cornersize, fill=False, resolution=('div', 4)), shader='fill')
		sch.set(shader='line')
		sch.add(o+size*(gap+cornersize)*z)
		sch.add(attach_end, space=world_solid(self.solids[1]))

	return sch

PointSlider(solids, axis, local=None)

Bases: Joint

Joint for rotation all around a point belonging to a plane.

pointslider joint

Classical definition: Punctiform/Sphere-Plane (axis) The initial state does not require more data The class holds a normal axis for the plane side, and a point for the sphere side (that defaults to the axis' origin)

Source code in madcad/joints.py
616
617
618
619
620
621
622
623
624
625
626
627
628
629
def __init__(self, solids, axis, local=None):
	self.solids = solids
	self.axis = axis
	local = local or axis

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
	else:
		raise TypeError("PointSlider can only be placed on Axis or mat4")
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

axis = axis instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

default = [0] * 6 class-attribute instance-attribute

increment = [inf] * 2 + [0.5] * 4 class-attribute instance-attribute

bounds = ([-inf] * 2 + [-2] * 4, [inf] * 2 + [2] * 4) class-attribute instance-attribute

direct(parameters)

Source code in madcad/joints.py
635
636
637
638
def direct(self, parameters):
	translation = vec2(parameters[0:2])
	rotation = quat(parameters[2:6])
	return self.post * translate(vec3(translation, 0)) * mat4(rotation) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
640
641
642
643
644
645
def inverse(self, matrix, close=None):
	m = affineInverse(self.post) * matrix * affineInverse(self.pre)
	return (
		*vec2(m[3]),
		*quat(m),
		)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, kinematic_color

	size = settings.display['joint_size']
	radius = size * 0.2
	resolution = ('div', 16)
	sch = Scheme()

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size),
		)
	square = gt.parallelogram(x*size, y*size, origin=o+radius*z, alignment=0.5)
	sch.add(square.outlines(), shader='line')
	sch.add(square, shader='ghost')

	if attach_start:
		attach = o+radius*z
		sch.add([attach, attach+z*0.1*size, attach+(x+y)*0.1*size], shader='fill')
		sch.add([attach+cornersize*size*z, attach_start], shader='line')

	center = affineInverse(self.pre)[3].xyz
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(center), maxsize/size),
		)
	sch.add(gt.icosphere(center, radius, resolution), shader='ghost')

	if attach_end:
		x,y,z = dirbase(attach_end)
		attach = radius*z
		sch.add([attach, attach+z*cornersize*size, attach+(x+y)*cornersize*size], shader='fill')
		sch.add([attach+cornersize*size*z, attach_start], shader='line')

	return sch

EdgeSlider(solids, axis, local=None)

Bases: Joint

Joint for rotation all around a, edge belonging to a plane.

Classical definition: Punctiform/Sphere-Plane (axis) The initial state does not require more data The class holds a normal axis for the plane side, and a point for the sphere side (that defaults to the axis' origin)

Source code in madcad/joints.py
695
696
697
698
699
700
701
702
703
704
705
def __init__(self, solids, axis, local=None):
	self.solids = solids
	self.axis = axis
	local = local or axis

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
	else:
		raise TypeError("EdgeSlider can only be placed on Axis or mat4")
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

axis = axis instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

default = [0] * 4 class-attribute instance-attribute

increment = [inf] * 2 + [1] * 2 class-attribute instance-attribute

bounds = ([-inf] * 4, [inf] * 4) class-attribute instance-attribute

direct(parameters)

Source code in madcad/joints.py
711
712
713
714
def direct(self, parameters):
	translation = vec2(parameters[0:2])
	rotation = quat(vec3(*parameters[2:4], 0))
	return self.post * translate(vec3(translation, 0)) * mat4(rotation) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
716
717
718
719
720
721
722
723
def inverse(self, matrix, close=None):
	m = affineInverse(self.post) * matrix * affineInverse(self.pre)
	q = quat(m)
	return (
		*vec2(m[3]),
		pitch(q),
		roll(q),
		)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, kinematic_color

	size = settings.display['joint_size']
	radius = 0.2*size
	resolution = ('div', 16)
	sch = Scheme()

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size),
		)
	square = gt.parallelogram(x*size, y*size, origin=o+radius*z, alignment=0.5)
	sch.add(square.outlines(), shader='line')
	sch.add(square, shader='ghost')

	if attach_start:
		attach = o+radius*z
		sch.add([attach, attach+cornersize*size*z, attach+cornersize*size*(x+y)], shader='fill')
		sch.add([o+cornersize*size*z, attach_start], shader='line')

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size),
		)
	cylinder = gt.cylinder(o-x*0.5*size, o+x*0.5*size, radius, fill=False, resolution=resolution)
	sch.add(cylinder, shader='ghost')
	sch.add(cylinder.outlines(), shader='line')

	if attach_end:
		x,y,z = dirbase(noproject(attach_end, x))
		attach = radius*z
		sch.add([attach, attach+z*cornersize*size, attach+(x+y)*cornersize*size], shader='fill')

	return sch

Ring(solids, center, local=None)

Bases: Joint

ring joint

Source code in madcad/joints.py
769
770
771
772
773
774
775
776
777
778
779
780
781
def __init__(self, solids, center, local=None):
	self.solids = solids
	local = local or center

	if isinstance(center, mat4):
		self.pre = center
		self.post = local
	elif isinstance(center, vec3):
		self.pre = translate(-center)
		self.post = translate(local)
	else:
		raise TypeError("ball can only be placed on a vec3 or mat4")
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

pre = center instance-attribute

post = local instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

bounds = ((-inf, -1, -1, -1, -1), (inf, 1, 1, 1, 1)) class-attribute instance-attribute

increment = (inf, 0.5, 0.5, 0.5, 0.5) class-attribute instance-attribute

default = (0, 1, 0, 0, 0) class-attribute instance-attribute

direct(orient)

Source code in madcad/joints.py
787
788
def direct(self, orient):
	return self.post * translate(params[0]) * mat4(quat(params[1:5])) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
790
791
def inverse(self, matrix, close=None):
	return quat(affineInverse(self.post) * matrix * affineInverse(self.pre))

transmit(force, parameters=None, velocity=None)

Source code in madcad/joints.py
793
794
def transmit(self, force, parameters=None, velocity=None):
	return Screw(vec3(0), force.momentum, self.center)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, kinematic_color

	from .primitives import ArcCentered

	size = settings.display['joint_size']
	radius = size/3
	sch = Scheme()
	resolution = ('div', 16)

	center = self.post[3].xyz
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(center), maxsize/size))
	if attach_start:
		x,y,z = dirbase(attach_end - center)
	else:
		x,y,z = mat3()
	profile = ArcCentered(Axis(center,y), center+x*radius, center-z*radius).mesh(resolution=resolution)
	emisphere = gt.revolution(profile, Axis(center,z), resolution)
	sch.add(emisphere, shader='ghost')
	sch.add(emisphere.outlines(), shader='line')

	center = affineInverse(self.pre)[3].xyz
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(center), maxsize/size))
	sch.add(gt.icosphere(center, radius*0.8, resolution), shader='ghost')

	return sch

Universal(solids, axis, local=None, bounds=None)

Bases: Joint

universal joint

Source code in madcad/joints.py
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
def __init__(self, solids, axis, local=None, bounds=None):
	self.solids = solids
	local = local or axis

	if bounds is not None:
		self.bounds = bounds

	if isinstance(axis, mat4):
		self.post = axis
		self.pre = affineInverse(local)
	elif isinstance(axis, Axis):
		self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
		self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
	else:
		raise TypeError('Universal joint can only be placed on an Axis or a mat4')
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

post = axis instance-attribute

pre = affineInverse(local) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

bounds = (vec2(-inf), vec2(inf)) class-attribute instance-attribute

increment = vec2(1) class-attribute instance-attribute

default = vec2(0) class-attribute instance-attribute

direct(orient)

Source code in madcad/joints.py
854
855
def direct(self, orient):
	return self.post * mat4(quat(vec3(orient, 0))) * self.pre

inverse(matrix, close=None)

Source code in madcad/joints.py
857
858
859
def inverse(self, matrix, close=None):
	m = quat(affineInverse(self.post) * matrix * affineInverse(self.pre))
	return vec2(pitch(m), yaw(m))

grad(orient)

Source code in madcad/joints.py
861
862
863
864
865
866
def grad(self, orient):
	pitch, yaw = orient
	return (
		self.post * drotate(pitch, X) * self.pre,
		self.post * drotate(pitch, Y) * self.pre,
		)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import scale_solid, world_solid, kinematic_color
	from .primitives import ArcCentered

	size = settings.display['joint_size']
	radius = size/3
	sch = Scheme()
	resolution = ('div', 16)

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = scale_solid(self.solids[0], fvec3(o), maxsize/size))
	if attach_start:
		o = self.post[3].xyz
		x,y,z = dirbase(attach_end - center, x)
		sch.add(attach_start, space=world_solid(self.solids[0]))
		sch.add(o - z*radius)
	sch.add(ArcCentered(Axis(o,x), y*radius, -y*radius).mesh(resolution), shader='line')
	sch.add([y, -y])

	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = scale_solid(self.solids[1], fvec3(o), maxsize/size))
	x,y,z,o = affineInverse(self.pre)
	if attach_end:
		o = affineInverse(self.pre)[3].xyz
		x,y,z = dirbase(attach_end - center, y)
		sch.add(attach_end, space=world_solid(self.solids[1]))
		sch.add(o - z*radius)
	sch.add(ArcCentered(Axis(o,y), x*radius, -x*radius).mesh(resolution), shader='line')
	sch.add([x, -x])

	return sch

ConstantVelocity(*args, default=0, **kwargs)

Bases: Joint

not implemented yet

Source code in madcad/kinematic/solver.py
75
76
77
78
79
80
def __init__(self, *args, default=0, **kwargs):
	if isinstance(args[0], Solid) and isinstance(args[1], Solid):
		self.solids = args[:2]
		args = args[2:]
	self.default = default
	self.init(*args, **kwargs)

Complex joints

Project(solids, projection, target)

Bases: Joint

not implemented yet

Source code in madcad/joints.py
915
916
def __init__(self, solids, projection:mat4, target:mat4):
	raise NotImplementedError("In development")

Rack(solids, radius, rack, axis)

Bases: Joint

Rack to gear interaction

radius is the ratio between the gear rotation and the rack translation

Attributes:

Name Type Description
radius

ratio between the gear rotation and the rack translation

rack

rack axis tangent to the gear

axis

gear axis

Source code in madcad/joints.py
929
930
931
932
933
934
935
936
937
def __init__(self, solids, radius:float, rack:Axis, axis):
	self.solids = solids
	self.radius = radius
	self.axis = axis
	self.rack = rack
	self.pre = mat4(quat(axis[1], Z)) * translate(-axis[0])
	self.post = translate(rack[0]) * mat4(quat(X, rack[1]))
	self.position = self.rack[0], self.axis[0]
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

radius = radius instance-attribute

axis = axis instance-attribute

rack = rack instance-attribute

pre = mat4(quat(axis[1], Z)) * translate(-axis[0]) instance-attribute

post = translate(rack[0]) * mat4(quat(X, rack[1])) instance-attribute

position = (self.rack[0], self.axis[0]) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

bounds = (-inf, inf) class-attribute instance-attribute

increment = 1 class-attribute instance-attribute

default = 0 class-attribute instance-attribute

direct(translation)

Source code in madcad/joints.py
943
944
def direct(self, translation):
	return self.post * translate(translation*X) * rotate(-translation/self.radius,Z) * self.pre

grad(translation)

Source code in madcad/joints.py
946
947
948
949
950
def grad(self, translation):
	return (
		+ self.post * dtranslate(X) * rotate(-translation/self.radius,Z) * self.pre
		+ self.post * translate(translation*X) * drotate(-translation/self.radius,Z)/-self.radius * self.pre
		)

inverse(matrix, close=None)

Source code in madcad/joints.py
952
953
954
def inverse(self, matrix, close=None):
	m = affineInverse(self.post) * matrix * affineInverse(self.pre)
	return atan(*m[0].xy)

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import world_solid, kinematic_color
	from .generation import revolution
	from .primitives import Circle, Segment
	sch = Scheme()

	x,y,z,o = dmat4x3(self.post)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = world_solid(self.solids[0]))
	sch.add([o-self.radius*y-self.radius*x, o-self.radius*y+self.radius*x], shader='line')

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	h = 0.1*self.radius*z
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = world_solid(self.solids[1]))
	sch.add(Circle(Axis(o,z), self.radius).mesh(), shader='line')
	sch.add(revolution(Segment(o+self.radius*x+h, o+self.radius*x-h), Axis(o,z)), shader='ghost')

	return sch

Gear(solids, ratio, centerline, axis, local)

Bases: Joint

Gear interaction between two solids.

ratio is the factor from the rotation of s1 to the rotation of s2 The two pinions are considered circular, but no assumption is made on their radius or relative inclination. The interaction is symetric.

Attributes:

Name Type Description
ratio

the gear rotation transmission ratio

centerline

the relative positioning of the gears axis, could be 'float', vec3, mat3, quat, mat4

axis

first gear axis

local

second gear axis

Source code in madcad/joints.py
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
def __init__(self, solids, ratio:float, centerline:mat4, axis, local):
	self.solids = solids
	self.ratio = ratio
	if isinstance(centerline, (int,float)):
		centerline = centerline*X
	self.centerline = transform(centerline)
	self.axis = axis
	self.pre = mat4(quat(local[1], Z)) * translate(-local[0])
	self.post = translate(axis[0]) * mat4(quat(Z, axis[1]))
	self.position = self.axis[0], local[0]
	self.scale = max(glm.abs(self.post[3]))

solids = solids instance-attribute

ratio = ratio instance-attribute

centerline = transform(centerline) instance-attribute

axis = axis instance-attribute

pre = mat4(quat(local[1], Z)) * translate(-local[0]) instance-attribute

post = translate(axis[0]) * mat4(quat(Z, axis[1])) instance-attribute

position = (self.axis[0], local[0]) instance-attribute

scale = max(glm.abs(self.post[3])) instance-attribute

bounds = (-inf, inf) class-attribute instance-attribute

increment = 1 class-attribute instance-attribute

default = 0 class-attribute instance-attribute

direct(angle)

Source code in madcad/joints.py
1013
1014
def direct(self, angle):
	return self.post * rotate(angle,Z) * self.centerline * rotate(-self.ratio*angle,Z) * self.pre

grad(angle)

Source code in madcad/joints.py
1016
1017
1018
1019
1020
def grad(self, angle):
	return (
		+ self.post * drotate(angle,Z) * self.centerline * rotate(-self.ratio*angle,Z) * self.pre
		+ self.post * rotate(angle,Z) * self.centerline * drotate(-self.ratio*angle,Z)*-self.ratio * self.pre
		)

inverse(matrix, close=None)

Source code in madcad/joints.py
1022
1023
1024
1025
def inverse(self, matrix, close=None):
	m = affineInverse(self.post) * matrix * affineInverse(self.pre)
	angle = atan(*m[0].xy) / (1+self.ratio)
	return (angle - close + pi) % (2*pi) - pi

scheme(index, maxsize, attach_start, attach_end)

Source code in madcad/joints.py
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
def scheme(self, index, maxsize, attach_start, attach_end):
	from .scheme import Scheme
	from .kinematic.displays import world_solid, kinematic_color
	from .generation import revolution
	from .primitives import Circle, Segment
	sch = Scheme()

	# radial vector
	r0 = length(self.centerline[3].xy) / abs(self.centerline[2].z - 1/self.ratio)
	r1 = r0 / abs(self.ratio)

	x,y,z,o = dmat4x3(self.post)
	h = 0.1*min(r0, r1) * (z * r0 + self.centerline[2].xyz * r1) / (r0 + r1)
	sch.set(
		track = index[self.solids[0]], 
		color = kinematic_color(index[self.solids[0]]),
		space = world_solid(self.solids[0]))
	sch.add(Circle(Axis(o,z), r0).mesh(), shader='line')
	sch.add(revolution(Segment(o+r0*x+h, o+r0*x-h), Axis(o,z)), shader='ghost')

	x,y,z,o = dmat4x3(affineInverse(self.pre))
	h = 0.1*min(r0, r1) * (self.centerline[2].xyz * r0 + z * r1) / (r0 + r1)
	sch.set(
		track = index[self.solids[1]], 
		color = kinematic_color(index[self.solids[1]]),
		space = world_solid(self.solids[1]))
	sch.add(Circle(Axis(o,z), r1).mesh(), shader='line')
	sch.add(revolution(Segment(o+r1*x+h, o+r1*x-h), Axis(o,z)), shader='ghost')

	return sch

Helicoid(s0, s1, step, b0, b1=None, position=None)

Bases: Joint

Screw a solid into an other.

helicoid joint

step is the translation distance needed for that one solid turn by 2*pi around the other The interaction is symetric.

not implemented yet

Source code in madcad/joints.py
1069
1070
1071
1072
1073
1074
1075
def __init__(self, s0, s1, step, b0, b1=None, position=None):
	self.step = step	# m/tr
	self.solids = s0, s1
	if isaxis(b0):			b0 = b0[0], *dirbase(b0[1])[:2]
	if b1 and isaxis(b1):	b1 = b1[0], *dirbase(b1[1])[:2]
	self.bases = b0, b1 or b0
	self.position = position or (self.bases[0][0], self.bases[1][0])

step = step instance-attribute

solids = (s0, s1) instance-attribute

bases = (b0, b1 or b0) instance-attribute

position = position or (self.bases[0][0], self.bases[1][0]) instance-attribute

direct(depth)

Source code in madcad/joints.py
1077
1078
def direct(self, depth):
	raise NotImplementedError("In development")

inverse(matrix, close=None)

Source code in madcad/joints.py
1080
1081
def inverse(self, matrix, close=None):
	raise NotImplementedError("In development")

scheme(solid, size, junc)

Source code in madcad/joints.py
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
def scheme(self, solid, size, junc):
	if solid is self.solids[0]:
		radius = size/4
		o,x,y = self.bases[0]
		z = cross(x,y)
		center = o + project(self.position[0]-o, z)
		cyl = generation.extrusion(
					web(primitives.Circle(
						(center-z*size*0.5, z), 
						radius, 
						resolution=('div', 16),
						)),
					z*size, 
					)
		l = len(cyl.points)
		v = junc - center
		v = normalize(noproject(v,z))
		if glm.any(isnan(v)):
			v,_,_ = dirbase(z)
		p = center + v*size/4
		cyl.points.append(p)
		cyl.points.append(p + z*size*cornersize)
		cyl.points.append(p + v*size*cornersize)
		cyl.points.append(junc)

		return Scheme(
				cyl.points, 
				cyl.faces, 
				[(l,l+1,l+2)], 
				(	[(l, l+2), (l+2, l+3)] 
				+	[(i-1,i) for i in range(1,l//2)] 
				+	[(i-1,i) for i in range(l//2+1,l)] 
				+	[(l//2-1,0), (l-1,l//2)]),
				)

	elif solid is self.solids[1]:
		radius = size/6
		o,x,y = self.bases[1]
		z = cross(x,y)
		center = o + project(self.position[1]-o, z)
		attach = side = z * size

		heli = []
		div = 32
		a = 4*pi
		for i in range(-div,div+1):
			t = i/div
			heli.append( radius*(cos(a*t)*x + sin(a*t)*y) + center + side*t )
		heli.extend([center+side, junc])
		heli = web(Wire(heli))
		return Scheme(heli.points, [], [], heli.edges)

Mesh-based joints

Cam(*args, default=0, **kwargs)

Bases: Joint

not implemented yet

Source code in madcad/kinematic/solver.py
75
76
77
78
79
80
def __init__(self, *args, default=0, **kwargs):
	if isinstance(args[0], Solid) and isinstance(args[1], Solid):
		self.solids = args[:2]
		args = args[2:]
	self.default = default
	self.init(*args, **kwargs)

Contact(*args, default=0, **kwargs)

Bases: Joint

not implemented yet

Source code in madcad/kinematic/solver.py
75
76
77
78
79
80
def __init__(self, *args, default=0, **kwargs):
	if isinstance(args[0], Solid) and isinstance(args[1], Solid):
		self.solids = args[:2]
		args = args[2:]
	self.default = default
	self.init(*args, **kwargs)