Skip to content

standard -- Common standard parametric parts

Module exposing many functions to create/visualize standard parts. Those are following the ISO (metric) specifications as often as possible.

Most parts are as easy to create as:

>>> nut(8)    # nut with nominal diameter 8mm
>>> screw(8, 16)   # screw with match diameter 8mm, and length 16mm

The parts usually have many optional parameters that default to usual recommended values. You can override this by setting the keyword arguments:

>>> screw(8, 16, head='button', drive='slot')

Numeric helpers

stfloor(x, precision=0.1)

Return a numeric value fitting x, with lower digits being the under closest digits from standard_digits

precision gives the relative tolerance interval for the returned number, so we are sure it lays in [x*(1-precision), x]

Source code in madcad/standard.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def stfloor(x, precision=0.1):
	''' Return a numeric value fitting x, with lower digits being the under closest digits from `standard_digits`

		`precision` gives the relative tolerance interval for the returned number, so we are sure it lays in `[x*(1-precision), x]`
	'''
	if hasattr(x, '__getitem__'):
		return type(x)(stfloor(e)  for e in x)
	if not isfinite(x):
		return x
	if not x:
		return x
	s, x = sign(x), abs(x)

	base = 10
	magnitude = base **floor(log(x) / log(base))
	ratio = x / magnitude

	for j in range(2 + int(ceil(-log(precision) / log(base)))):
		for st in standard_digits:
			candidate = floor(ratio) + st
			if candidate > ratio + 2*NUMPREC:
				continue
			if ratio*(1-precision) + NUMPREC <= candidate:
				return candidate * magnitude * s
		magnitude /= base
		ratio *= base
	raise RuntimeError('failed to converge, this is a bug')

stceil(x, precision=0.1)

Return a numeric value fitting x, with lower digits being the above closest digits from standard_digits

precision gives the relative tolerance interval for the returned number, so we are sure it lays in [x, x*(1+precision)]

Source code in madcad/standard.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
def stceil(x, precision=0.1):
	''' Return a numeric value fitting x, with lower digits being the above closest digits from `standard_digits`

		`precision` gives the relative tolerance interval for the returned number, so we are sure it lays in `[x, x*(1+precision)]`
	'''
	if hasattr(x, '__getitem__'):
		return type(x)(stceil(e)  for e in x)
	if not isfinite(x):
		return x
	s, x = sign(x), abs(x)

	base = 10
	magnitude = base**ceil(log(x) / log(base))
	ratio = x / magnitude

	for j in range(2 + int(ceil(-log(precision) / log(base)))):
		for st in standard_digits:
			candidate = floor(ratio) + st
			if candidate < ratio - 2*NUMPREC:
				continue
			if ratio*(1+precision) + NUMPREC >= candidate:
				return candidate * magnitude * s
		magnitude /= base
		ratio *= base
	raise RuntimeError('failed to converge, this is a bug')

Screw stuff

nut(d, type='hex', detail=False)

Create a standard nut model using the given shape type

nut

Parameters:

Name Type Description Default
d

nominal diameter of the matching screw

required
type

the nut shape

'hex'
detail

if True, the thread surface will be generated, else it will only be a cylinder

False

If d alone is given, the other parameters default to the ISO specs: https://www.engineersedge.com/iso_flat_washer.htm

Currently only shape 'hex' is available.

Source code in madcad/standard.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
@cachefunc
def nut(d, type='hex', detail=False) -> Mesh:
	''' Create a standard nut model using the given shape type

	![nut](../screenshots/hexnut.png)

	Parameters:
		d:        nominal diameter of the matching screw
		type:     the nut shape
		detail:   if True, the thread surface will be generated, else it will only be a cylinder

	If `d` alone is given, the other parameters default to the ISO specs: https://www.engineersedge.com/iso_flat_washer.htm

	Currently only shape 'hex' is available.
	'''
	args = standard_hexnuts[bisect(standard_hexnuts, d, key=itemgetter(0))]
	if args[0] != d:
		raise ValueError('no standard nut for diameter {}'.format(d))
	return hexnut(*args)

screw(d, length, filet_length=None, head='SH', drive=None, detail=False)

Create a standard screw using the given drive and head shapes

screw

Parameters:

Name Type Description Default
d

nominal diameter of the screw

required
length

length from the screw head to the tip of the screw

required
filet_length

length of the filet on the screw (from the tip), defaults to length

None
head

name of the screw head shape

'SH'
drive

name of the screw drive shape

None
detail

if True, the thread surface will be generated, else it will only be a cylinder

False

It's also possible to specify head and drive at once, using their codenames:

    >>> screw(5, 16, head='SHT')   # socket head and torx drive
Available screw heads
  • socket (default)
  • button
  • flat (aka. cone)
Available screw drives
  • hex
  • torx (not yet available)
  • phillips (cross) (not yet available)
  • slot
All possible shapes
Source code in madcad/standard.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@cachefunc
def screw(d, length, filet_length=None, head='SH', drive=None, detail=False):
	''' Create a standard screw using the given drive and head shapes

	![screw](../screenshots/screw.png)

	Parameters:
		d:             nominal diameter of the screw
		length:        length from the screw head to the tip of the screw
		filet_length:  length of the filet on the screw (from the tip), defaults to `length`

		head:          name of the screw head shape
		drive:			name of the screw drive shape
		detail:   if True, the thread surface will be generated, else it will only be a cylinder

	It's also possible to specify head and drive at once, using their codenames:

		>>> screw(5, 16, head='SHT')   # socket head and torx drive

	Available screw heads:
		* socket (default)
		* button
		* flat (aka. cone)

	Available screw drives:
		* hex
		* torx  *(not yet available)*
		* phillips (cross)  *(not yet available)*
		* slot

	All possible shapes:
		* see wikipedia for the [drive types](https://en.wikipedia.org/wiki/List_of_screw_drives)
		* see [here for a guide of what to use](https://www.homestratosphere.com/types-of-screws/)
		* see wikipedia for [standard screw thread](https://en.wikipedia.org/wiki/ISO_metric_screw_thread)


	'''
	if filet_length is None:	filet_length = length - 0.05*d
	elif length < filet_length:	raise ValueError('filet_length must be smaller than length')

	head, drive = screw_spec(head, drive)
	head = globals()['screwhead_'+head](d)
	if drive:
		drive = globals()['screwdrive_'+drive](d) .transform(boundingbox(head).max[2]*Z)
		head = intersection(head, drive)

	r = 0.5*d
	axis = Axis(O, Z, interval=(-length,r))
	top = head.box().min.z
	body = revolution(wire([
					vec3(r, 0, top),
					vec3(r, 0, min(top, -length+filet_length)),
					vec3(r, 0, -length+r*0.2),
					vec3(r*0.8, 0, -length),
					vec3(0, 0, -length),
					]) .segmented())
	screw = (body + head).finish().option(color=settings.colors['bolt'])
	return Solid(part=screw, axis=axis)

washer(d, e=None, h=None)

Create a standard washer.

washer

Washers are useful to offset screws and avoid them to scratch the mount part

Parameters:

Name Type Description Default
d

the nominal interior diameter (screw or anything else), the exact washer interior is slightly bigger

required
e

exterior diameter

None
h

height/thickness

None

If d alone is given, the other parameters default to the ISO specs: https://www.engineersedge.com/iso_flat_washer.htm

Source code in madcad/standard.py
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
@cachefunc
def washer(d, e=None, h=None) -> Mesh:
	''' Create a standard washer.

	![washer](../screenshots/washer.png)

	Washers are useful to offset screws and avoid them to scratch the mount part

	Parameters:
		d:        the nominal interior diameter (screw or anything else),
		           the exact washer interior is slightly bigger
		e:        exterior diameter
		h:        height/thickness

	If `d` alone is given, the other parameters default to the ISO specs: https://www.engineersedge.com/iso_flat_washer.htm
	'''
	if e is None and h is None:
		args = standard_washers[bisect(standard_washers, d, key=itemgetter(0))]
		if abs(args[0] - d)/d < 0.2:
			_, d, e, h = args
		else:
			raise ValueError('no standard nut for the given diameter')
	else:
		d *= 1.1
		if e is None:	e = d*2
		if h is None:	h = d*0.1

	return Solid(
				part=thicken(revolution(web([e/2*X, d/2*X])), h).option(color=settings.colors['bolt']),
				top=Axis(h*Z, Z, interval=(0,h)),
				bottom=Axis(O, -Z, interval=(0,h)),
				)

bolt(a, b, dscrew, washera=False, washerb=False, nutb=True)

convenient function to create a screw, nut and washers assembly

bolt

Parameters:

Name Type Description Default
a vec3

the screw placement

required
b vec3

the nut placement

required
dscrew float

the screw d parameter

required
washera

if True, place a washer between the screw head at a

False
washerb

if True, place a washer between the nut at b

False
butb

if True, place a nut at b

required
Source code in madcad/standard.py
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
def bolt(a: vec3, b: vec3, dscrew: float, washera=False, washerb=False, nutb=True) -> Solid:
	''' convenient function to create a screw, nut and washers assembly

	![bolt](../screenshots/bolt.png)

	Parameters:
		a:  the screw placement
		b:  the nut placement
		dscrew:  the screw `d` parameter
		washera:  if True, place a washer between the screw head at `a`
		washerb:  if True, place a washer between the nut at `b`
		butb:    if True, place a nut at `b`
	'''
	dir = normalize(b-a)
	rwasher = washer(dscrew)
	thickness = rwasher['part'].box().size.z
	rscrew = screw(dscrew, stceil(distance(a,b) + 1.2*dscrew, precision=0.2))
	#rscrew['annotations'] = [
				#note_distance(O, -stceil(distance(a,b) + 1.2*dscrew)*Z, offset=2*dscrew*X),
				#note_radius(rscrew['part'].group(0)),
				#]
	result = Solid(
			a = a,
			b = b,
			dscrew = dscrew,
			screw = rscrew.place((Revolute, rscrew['axis'], Axis(a-thickness*dir*int(washera), -dir))),
			)
	if washera:
		result['washera'] = rwasher.place((Revolute, rwasher['top'], Axis(a, dir)))
	if washerb:
		result['washerb'] = rwasher.place((Revolute, rwasher['top'], Axis(b, -dir)))
	if nutb:
		rnut = nut(dscrew)
		result['nut'] = rnut.place((Revolute, rnut['top'], Axis(b+thickness*dir*int(washerb), -dir)))
	return result

Coilsprings

coilspring_compression(length, d=None, thickness=None, solid=True)

Return a Mesh model of a croilspring meant for use in compression

coilspring_compression

Parameters:

Name Type Description Default
length

the distance between its two ends

required
d

the exterior diameter (the coilspring can fit in a cylinder of that diameter)

None
thickness

the wire diameter of the spring (useless if solid is disabled)

None
solid

disable it to get only the tube path of the coil, and have a Wire as return value

True
Source code in madcad/standard.py
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
@cachefunc
def coilspring_compression(length, d=None, thickness=None, solid=True):
	''' Return a Mesh model of a croilspring meant for use in compression

	![coilspring_compression](../screenshots/coilspring-compression.png)

	Parameters:
		length:     the distance between its two ends
		d:          the exterior diameter (the coilspring can fit in a cylinder of that diameter)
		thickness:  the wire diameter of the spring (useless if solid is disabled)
		solid:      disable it to get only the tube path of the coil, and have a `Wire` as return value
	'''
	if not d:			d = length*0.2
	if not thickness:	thickness = d*0.1
	r = d/2 - thickness		# coil radius
	e = r					# coil step
	div = settings.curve_resolution(d*pi, 2*pi)
	step = 2*pi/(div+1)

	t = 0

	t0, z0 = t, -0.5*length
	top = []
	for t in linrange(t0, t0 + 4*pi, step):
		top.append( vec3(r*cos(t), r*sin(t), z0 + (t-t0)/(2*pi) * thickness) )

	t0, z0 = t, -0.5*length + 2*thickness
	coil = []
	for t in linrange(t0, t0 + 2*pi * (length-4*thickness) / e, step):
		coil.append( vec3(r*cos(t), r*sin(t), z0 + (t-t0)/(2*pi) * e) )

	t0, z0 = t, 0.5*length - 2*thickness
	bot = []
	for t in linrange(t0, t0 + 4*pi, step):
		bot.append( vec3(r*cos(t), r*sin(t), z0 + (t-t0)/(2*pi) * thickness) )

	path = Wire(top) + Wire(coil).qualify('spring') + Wire(bot)

	if not solid:
		return path

	return Solid(
			part=tube(
				fill(Circle(
					(path[0],Y),
					thickness/2,
					resolution=('div',6)
					)) .flip(),
				path,
				),
			axis=Axis(O, Z, interval=(-length/2, length/2)),
			top=0.5*length*Z,
			bottom=-0.5*length*Z,
			)

coilspring_tension(length, d=None, thickness=None, solid=True)

Return a Mesh model of a croilspring meant for use in tension

coilspring_tension

Parameters:

Name Type Description Default
length

the distance between its two hooks

required
d

the exterior diameter (the coilspring can fit in a cylinder of that diameter)

None
thickness

the wire diameter of the spring (useless if solid is disabled)

None
solid

disable it to get only the tube path of the coil, and have a Wire as return value

True
Source code in madcad/standard.py
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
@cachefunc
def coilspring_tension(length, d=None, thickness=None, solid=True):
	''' Return a Mesh model of a croilspring meant for use in tension

	![coilspring_tension](../screenshots/coilspring-tension.png)

	Parameters:
		length:     the distance between its two hooks
		d:          the exterior diameter (the coilspring can fit in a cylinder of that diameter)
		thickness:  the wire diameter of the spring (useless if solid is disabled)
		solid:      disable it to get only the tube path of the coil, and have a `Wire` as return value
	'''
	if not d:			d = length*0.2
	if not thickness:	thickness = d*0.1
	r = d/2 - thickness		# coil radius
	e = r					# coil step

	# separate the coilspring in 3 parts:  the coil and the 2 hooks at both ides
	spring_length = length - 2*r
	ncoil = floor(spring_length / thickness) - 0.5
	hold = 0.5*length - r

	# create coil
	div = settings.curve_resolution(d*pi, 2*pi)
	step = 2*pi/(div+1)
	z0 = -0.5 * ncoil * thickness
	coil = Wire([	vec3(r*cos(t), r*sin(t), z0 + t/(2*pi) * thickness)
					for t in linrange(0, 2*pi * ncoil, step) ]) .qualify('spring')
	# create path with hooks
	path = wire([
				ArcCentered((-0.5*length*Z, X), vec3(0, -r, -0.5*length), -hold*Z),
				ArcThrough(-hold*Z, (-hold*Z + coil[0])*0.5 - 0.5*r*Y, coil[0]),
				coil,
				ArcThrough(coil[-1], (hold*Z + coil[-1])*0.5 - 0.5*r*Y, hold*Z),
				ArcCentered((0.5*length*Z, X), hold*Z, vec3(0, -r, 0.5*length)),
				])
	if not solid:
		return path

	return Solid(
			part=tube(
				fill(Circle(
					(path[0],Z),
					thickness/2,
					resolution=('div',6)
					)),
				path,
				),
			axis=Axis(O,Z, interval=(-length/2, length/2)),
			top=0.5*length*Z,
			bottom=-0.5*length*Z,
			)

coilspring_torsion(arm, angle=radians(45), d=None, length=None, thickness=None, hook=None, solid=True)

Return a Mesh model of a croilspring meant for use in torsion

coilspring_torsion

Parameters:

Name Type Description Default
arm

the arms length from the coil axis

required
length

the coil length (and distance between its hooks)

None
d

the exterior diameter (the coilspring can fit in a cylinder of that diameter)

None
thickness

the wire diameter of the spring (useless if solid is disabled)

None
hook

the length of arm hooks (negative for hooks toward the interior)

None
solid

disable it to get only the tube path of the coil, and have a Wire as return value

True
Source code in madcad/standard.py
795
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
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
@cachefunc
def coilspring_torsion(arm,
			angle=radians(45),
			d=None,
			length=None,
			thickness=None,
			hook=None,
			solid=True) -> Solid:
	''' Return a Mesh model of a croilspring meant for use in torsion

	![coilspring_torsion](../screenshots/coilspring-torsion.png)

	Parameters:
		arm:        the arms length from the coil axis
		length:     the coil length (and distance between its hooks)
		d:          the exterior diameter (the coilspring can fit in a cylinder of that diameter)
		thickness:  the wire diameter of the spring (useless if solid is disabled)
		hook:       the length of arm hooks (negative for hooks toward the interior)
		solid:      disable it to get only the tube path of the coil, and have a `Wire` as return value
	'''
	if not length:		length = arm*0.5
	if not d:			d = arm
	if not thickness:	thickness = d*0.1
	if not hook:		hook = -length
	r = d/2 - thickness		# coil radius
	e = r					# coil step
	angle = pi - angle

	# separate the coilspring in 3 parts:  the coil and the 2 hooks at both ides
	ncoil = ceil(length / thickness) + angle/(2*pi)

	# create coil
	div = settings.curve_resolution(d*pi, 2*pi)
	step = 2*pi/(div+1)
	z0 = -0.5 * ncoil * thickness
	coil = Wire([	vec3(-r*sin(t), r*cos(t), z0 + t/(2*pi) * thickness)
					for t in linrange(0, 2*pi * ncoil, step) ]) .qualify('spring')

	# create hooks
	c = thickness * sign(hook)
	if abs(c) > abs(hook):
		hook = c
	top = Wire([
			vec3(arm, 0, hook),
			vec3(arm, 0, c),
			vec3(arm-abs(c), 0, 0),
			vec3(0),
			]) .transform(coil[0])
	bot = (top
			.flip()
			.transform(scaledir(Z,-1)*scaledir(X,-1))
			.transform(angleAxis(angle, Z))
			)

	# create path
	path = top + coil + bot
	path.mergeclose()

	if not solid:
		return path

	return Solid(
			part=tube(
				fill(Circle(
					(path[0], normalize(path[0]-path[1])),
					thickness/2,
					resolution=('div',6),
					)),
				path,
				),
			axis=Axis(O,Z, interval=(-length/2, length/2)),
			top=path[0],
			bottom=path[-1],
			)

Bearings

bearing(dint, dext=None, h=None, circulating='ball', contact=0, hint=None, hext=None, sealing=False, detail=False)

Circulating bearings rely on rolling elements to avoid friction and widen the part life.

bearing

Its friction depends on the rotation speed but not on the current load.

See bearing specs at https://koyo.jtekt.co.jp/en/support/bearing-knowledge/

Parameters:

Name Type Description Default
dint

interior bore diameter

required
dext

exterior ring diameter

None
h

total height of the bearing

None
hint

height of the interior ring. Only for angled roller bearings

None
hext

height of the exterior ring. Only for angled roller bearings

None
circulating

The type of circulating element in the bearing

  • ball
  • roller
'ball'
contact

Contact angle (aka pressure angle). It decided what directions of force the bearing can sustain.

  • 0 for radial bearing
  • pi/2 for thrust (axial) bearings
  • 0 < contact < pi/2 for conic bearings
0
sealing

True if the bearing has a sealing side. Only for balls bearings with contact = 0

False
detail

If True, the returned model will have the circulating elements and cage, if False the returned element is just a bounding representation

False
Source code in madcad/standard.py
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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
@cachefunc
def bearing(dint, dext=None, h=None,
			circulating='ball',
			contact=0,
			hint=None, hext=None,
			sealing=False,
			detail=False) -> Solid:
	'''
	Circulating bearings rely on rolling elements to avoid friction and widen the part life.

	![bearing](../screenshots/bearing-bounded.png)

	Its friction depends on the rotation speed but not on the current load.

	See bearing specs at https://koyo.jtekt.co.jp/en/support/bearing-knowledge/

	Parameters:
		dint:	interior bore diameter
		dext:  exterior ring diameter
		h:     total height of the bearing

		hint:  height of the interior ring. Only for angled roller bearings
		hext:  height of the exterior ring. Only for angled roller bearings

		circulating:

			The type of circulating element in the bearing

			- ball
			- roller

		contact:

			Contact angle (aka pressure angle).
			It decided what directions of force the bearing can sustain.

			- `0` for radial bearing
			- `pi/2`  for thrust (axial) bearings
			- `0 < contact < pi/2` for conic bearings

		sealing:  True if the bearing has a sealing side. Only for balls bearings with `contact = 0`

		detail:   If True, the returned model will have the circulating elements and cage, if False the returned element is just a bounding representation
	'''
	if isinstance(dint, str):
		dint, dext, h = bearing_spec(dint)
	else:
		if not dext:	dext = 2*dint
		if not h:		h = 0.5*dint

	assert 0 < h <= dint < dext
	assert 0 <= contact

	if circulating == 'roller':
		if sealing:
			raise ValueError('sealing must be None for roller bearings')
		return bearing_roller(dint, dext, h, contact, hint, hext, detail)

	elif circulating == 'ball':
		if hint or hext:
			raise ValueError('hint and hext must be None for ball bearings')
		if abs(contact) < NUMPREC:
			return bearing_ball(dint, dext, h, sealing, detail)
		if abs(contact - 0.5*pi) < NUMPREC:
			if sealing:
				raise ValueError('sealing must be none for thrust bearings')
			return bearing_thrust(dint, dext, h, detail)
		else:
			raise ValueError('ball bearings must not be angled')

	else:
		raise ValueError('unknown circulating element {}'.format(repr(circulating)))

slidebearing(dint, h=None, thickness=None, shoulder=None, opened=False)

Slide bearings rely on gliding parts to ensure a good pivot. It's much cheaper than circulating bearings and much more compact. But needs lubricant and has a shorter life than circulating bearings. Its friction depends on the rotation speed and on the load.

Parameters:

Name Type Description Default
dint

interior diameter

required
h

exterior height (under shoulder if there is)

None
thickness

shell thickness, can be automatically determined

None
shoulder

distance from bore to shoulder tip, put 0 to disable

None
opened

enable to have a slight breach that allows a better fitting to the placement hole

False
Source code in madcad/standard.py
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
@cachefunc
def slidebearing(dint, h=None, thickness=None, shoulder=None, opened=False) -> Solid:
	'''
	Slide bearings rely on gliding parts to ensure a good pivot. It's much cheaper than circulating bearings and much more compact. But needs lubricant and has a shorter life than circulating bearings.
	Its friction depends on the rotation speed and on the load.

	Parameters:
		dint:       interior diameter
		h:          exterior height (under shoulder if there is)
		thickness:  shell thickness, can be automatically determined
		shoulder:   distance from bore to shoulder tip, put 0 to disable
		opened:     enable to have a slight breach that allows a better fitting to the placement hole
	'''
	if h is None:			h = 1.2*dint
	if thickness is None:	thickness = 0.05*dint
	rint = dint/2

	profile = Wire([
				vec3(rint,0,-h),
				vec3(rint,0, 0),
				])
	if shoulder:
		profile += Wire([ vec3(rint+shoulder, 0, 0) ])
		profile = profile.segmented()
		filet(profile, [1], radius=1.5*thickness, resolution=('div',2))

	axis = Axis(O,Z, interval=(-h,0))
	shape = revolution(profile, axis, 1.98*pi if opened else 2*pi)

	part = thicken(shape, thickness) .option(color=settings.colors['bearing'])
	line = (  select(part, vec3(-rint,0,-h), stopangle(pi/2))
			+ select(part, vec3(dint,dint,-h), stopangle(pi/2))
			)
	if not shoulder:
		line += (  select(part, vec3(-rint,0,0), stopangle(pi/2))
				 + select(part, vec3(dint,dint,0), stopangle(pi/2))
				)

	chamfer(part, line, width=0.5*thickness)
	return Solid(part=part, axis=axis)

Standard sections for extrusion

section_tslot(size=1, slot=None, thickness=None, depth=None)

Standard T-Slot section. That section features slots on each side to put nuts at any position.

section_tslot

Source code in madcad/standard.py
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
def section_tslot(size=1, slot=None, thickness=None, depth=None) -> Web:
	''' Standard T-Slot section. That section features slots on each side to put nuts at any position.

		![section_tslot](../screenshots/section_tslot.png)
	'''
	if slot is None:	slot = 0.3*size
	if thickness is None:	thickness = 0.08*size
	if depth is None:	depth = 0.2*size
	b = depth-thickness

	center = Circle((O,-Z), size/2-depth-2*thickness)
	base = wire([
		vec3(size/2, size/2, 0),
		vec3(size/2, slot/2+thickness, 0),
		vec3(size/2-thickness, slot/2, 0),
		vec3(size/2-thickness, slot/2+b, 0),
		vec3(size/2-thickness-depth+b, slot/2+b, 0),
		vec3(size/2-thickness-depth, slot/2, 0),
		]) .flip()
	base = (base + base.transform(scaledir(normalize(vec3(1,-1,0)), -1)) .flip() ).segmented()
	base = base + base.transform(scaledir(X, -1)) .flip()
	base = base + base.transform(scaledir(Y, -1)) .flip()
	section = web([
		center,
		base.close().segmented(),
		])
	filet(section, section.frontiers(5,7, 41,43, 31,29, 17,19), radius=thickness/2, resolution=('div',2))

	#notes = [
		#note_distance(base.points[2], base.points[5], offset=-c/2*Y),
		#note_distance(base.points[1], base.points[2], offset=-c/2*Y, project=X),
		#note_distance(base.points[2], base.points[2]*vec3(1,-1,1), offset=s*X),
		#note_distance(base.points[0], base.points[0]*vec3(1,-1,1), offset=2*s*X),
		#]

	return section.finish()

section_s(height=1, width=None, flange=None, thickness=None)

Standard S (short flange) section. Very efficient to support flexion efforts.

section_s

Source code in madcad/standard.py
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
def section_s(height=1, width=None, flange=None, thickness=None) -> Web:
	''' Standard S (short flange) section. Very efficient to support flexion efforts.

		![section_s](../screenshots/section_s.png)
	'''
	if width is None:	width = 0.4 * height
	if flange is None:	flange = 0.036 * height
	if thickness is None:	thickness = 0.054 * height
	assert width > 3*thickness+2*flange and height > 2*flange+2*thickness

	base = wire([
		vec3(width/2, height/2, 0),
		vec3(width/2, height/2-flange, 0),
		vec3(thickness/2, height/2-flange-0.1*(width/2-thickness/2), 0),
		]) .flip()
	base = base + base.transform(scaledir(X,-1)).flip()
	base = base + base.transform(scaledir(Y,-1)).flip()
	section = web(base.close().segmented())
	filet(section, section.frontiers(0,5,10,4,6,11), radius=thickness*0.4, resolution=('div',2))
	filet(section, section.frontiers(1,0,4,3,6,7,10,9), radius=flange, resolution=('div',2))

	#notes = [
		#note_distance(base.points[0], base.points[0]*vec3(1,-1,1), offset=2*flange*X),
		#note_distance(base.points[0], base.points[1], offset=flange*X),
		#note_distance(base.points[0], base.points[0]*vec3(-1,1,1), offset=flange*Y),
		#note_distance(thickness/2*X, -thickness/2*X),
		#]

	return section.finish()

section_w(height=1, width=None, flange=None, thickness=None)

Standard W (wide flange) section. It is slightly different than a S section in that the flanges are straight and are usally wider.

section_w

Source code in madcad/standard.py
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
def section_w(height=1, width=None, flange=None, thickness=None) -> Web:
	''' Standard W (wide flange) section. It is slightly different than a S section in that the flanges are straight and are usally wider.

		![section_w](../screenshots/section_w.png)
	'''
	if width is None:	width = 0.6 * height
	if flange is None:	flange = 0.036 * height
	if thickness is None:	thickness = 0.054 * height
	assert width > 3*thickness+2*flange and height > 2*flange+2*thickness

	base = wire([
		vec3(width/2, height/2, 0),
		vec3(width/2, height/2-flange, 0),
		vec3(thickness/2, height/2-flange, 0),
		]) .flip()
	base = (base + base.transform(scaledir(X,-1)).flip() ).segmented()
	base = base + base.transform(scaledir(Y,-1)).flip()
	base.close()
	section = web(base)
	filet(section, section.frontiers(0,5,10,4,6,11), radius=thickness*0.4, resolution=('div',2))
	filet(section, section.frontiers(1,0,4,3,6,7,10,9), radius=flange*0.5, resolution=('div',2))
	return section.finish()

section_l(a=1, b=None, thickness=None)

Standard L section

section_l

Source code in madcad/standard.py
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
def section_l(a=1, b=None, thickness=None) -> Wire:
	''' Standard L section

		![section_l](../screenshots/section_l.png)
	'''
	if b is None:	b = a
	if thickness is None:	thickness = 0.05*max(a,b)
	assert a > 3*thickness and b > 3*thickness

	section = wire([
		vec3(0, 0, 0),
		vec3(0, a, 0),
		vec3(thickness, a, 0),
		vec3(thickness, thickness, 0),
		vec3(b, thickness, 0),
		vec3(b, 0, 0),
		]) .close() .segmented() .flip()

	filet(section, [2,3,4], radius=thickness*0.8, resolution=('div',2))
	return section.finish()

section_c(height=1, width=None, thickness=None)

Standard C section

section_c

Source code in madcad/standard.py
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
def section_c(height=1, width=None, thickness=None) -> Web:
	''' Standard C section

		![section_c](../screenshots/section_c.png)
	'''
	if width is None:	width = 0.6*height
	if thickness is None:	thickness = 0.05*height
	assert width > 3*thickness

	base = wire([
		vec3(0, height/2, 0),
		vec3(width, height/2, 0),
		vec3(width, height/2-thickness, 0),
		vec3(thickness, height/2-thickness, 0),
		]) .flip()
	base = base + base.transform(scaledir(Y,-1)).flip()
	section = web(base.close().segmented())

	filet(section, section.frontiers(0,1,5,7,6), radius=0.8*thickness, resolution=('div',2))
	return section.finish()

Convenient shapes to integrate standard parts

screw_slot(axis, dscrew, rslot=None, hole=0.0, screw=0.0, expand=True, flat=False)

slot shape for a screw

screw_slot

the result can then be used in a boolean operation to reserve set a screw place in an arbitrary shape

Parameters:

Name Type Description Default
axis Axis

the screw axis placement, z toward the screw head (part exterior)

required
dscrew float

the screw diameter

required
rslot

the screw head slot radius

None
hole
  • if True, enables a cylindric hole for screw body of length dscrew*3
  • if float, it is the screw hole length
0.0
screw

if non zero, this is the length of a thiner portion of hole after hole, the diameter is adjusted so that the screw can screw in

0.0
expand
  • if True, enables slots sides
  • if float, it is the slot sides height
True
flat

if True, the slot will be conic do receive a flat head screw

False
Source code in madcad/standard.py
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
def screw_slot(axis: Axis, dscrew: float, rslot=None, hole=0., screw=0., expand=True, flat=False) -> Mesh:
	''' slot shape for a screw

	![screw_slot](../screenshots/screw_slot.png)

	the result can then be used in a boolean operation to reserve set a screw place in an arbitrary shape

	Parameters:
		axis:  the screw axis placement, z toward the screw head (part exterior)
		dscrew: the screw diameter
		rslot:  the screw head slot radius
		hole:
			- if `True`, enables a cylindric hole for screw body of length `dscrew*3`
			- if `float`, it is the screw hole length
		screw:  if non zero, this is the length of a thiner portion of hole after `hole`, the diameter is adjusted so that the screw can screw in
		expand:
			- if `True`, enables slots sides
			- if `float`, it is the slot sides height
		flat:   if True, the slot will be conic do receive a flat head screw
	'''
	if not rslot:	rslot = 1.1*dscrew
	o = axis[0]
	x,y,z = dirbase(axis[1])

	profile = []
	if expand:
		if isinstance(expand, bool):		expand = 2*rslot
		profile.append(o + rslot*x + expand*z)
	profile.append(o + rslot*x)
	if hole or screw:
		if flat:
			profile.append(o + 0.5*dscrew*(x-z) - (rslot-dscrew)*z)
			hole = max(hole, dot(o-profile[-1], z))
		else:
			profile.append(o + 0.5*dscrew*x)
		profile.append(o + 0.5*dscrew*x - hole*z)
		profile.append(o + 0.4*dscrew*x - min(hole+0.1*dscrew, hole+screw)*z)
		profile.append(o + 0.4*dscrew*x - (hole+screw)*z)
		profile.append(o - (hole+screw+0.4*dscrew)*z)
	else:
		profile.append(o)
	return revolution(wire(profile).segmented(), Axis(o,-z)).finish()

bolt_slot(a, b, dscrew, rslot=None, hole=True, expanda=True, expandb=True)

bolt shape for a screw

bolt_slot

musch like screw_slot() but with two endings

Parameters:

Name Type Description Default
a vec3

position of screw head

required
b vec3

position of nut

required
dscrew float

the screw diameter

required
rslot

the screw head slot radius

None
hole

enabled the cylindric hole between the head and nut slots

True
expanda, expandb
  • if True, enables slot sides on tip a or b
  • if float, it is the slot side height
required

Examples:

>>> a, b = vec3(...), vec3(...)
>>> bolts = bolt(a, b, 3)
>>> part_hole = bolt_slot(a, b, 3)
Source code in madcad/standard.py
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
def bolt_slot(a: vec3, b: vec3, dscrew: float, rslot=None, hole=True, expanda=True, expandb=True) -> Mesh:
	''' bolt shape for a screw

	![bolt_slot](../screenshots/bolt_slot.png)

	musch like `screw_slot()` but with two endings

	Parameters:
		a:  position of screw head
		b:  position of nut
		dscrew:  the screw diameter
		rslot:   the screw head slot radius
		hole:    enabled the cylindric hole between the head and nut slots
		expanda, expandb:
			- if `True`, enables slot sides on tip `a` or `b`
			- if `float`, it is the slot side height

	Examples:
		>>> a, b = vec3(...), vec3(...)
		>>> bolts = bolt(a, b, 3)
		>>> part_hole = bolt_slot(a, b, 3)
	'''
	if not rslot:	rslot = 1.3*dscrew
	x,y,z = dirbase(normalize(a-b))

	def one_slot(o,x,z, expand):
		profile = []
		if expand:
			if isinstance(expand, bool):		expand = 2*rslot
			profile.append(o + rslot*x + expand*z)
		profile.append(o + rslot*x)
		if hole:
			profile.append(o + 0.5*dscrew*x)
		else:
			profile.append(o)
		return wire(profile).segmented()

	return revolution(
			one_slot(a,x,z, expanda) + one_slot(b,x,-z, expandb).flip(),
			Axis(a,-z),
			).finish()

bearing_slot_exterior(axis, dext, height, shouldering=True, circlip=False, evade=True, expand=True)

slot for a bearing exterior ring, such as returned by bearing()

Parameters:

Name Type Description Default
axis Axis

bearing axis placement

required
dext float

bearing dext parameter

required
height float

bearing h parameter

required
shouldering

generate a shoulder to support the top side of the bearing's exterior ring

True
circlip

enable a slot for a circlip to support the bottom side of the bearing's exterior ring

False
evade

set expansion to evasive rather that straight

True
expand

expand the slot with evasive or straight surfaces to ease itnersection with other meshes

  • True enables expansion with a default length
  • float set the expansion distance
True
Source code in madcad/standard.py
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
def bearing_slot_exterior(axis: Axis, dext: float, height: float, shouldering=True, circlip=False, evade=True, expand=True):
	''' slot for a bearing exterior ring, such as returned by `bearing()`

	Parameters:
		axis:  bearing axis placement
		dext:  bearing `dext` parameter
		height: bearing `h` parameter
		shouldering:  generate a shoulder to support the top side of the bearing's exterior ring
		circlip: enable a slot for a circlip to support the bottom side of the bearing's exterior ring
		evade:  set expansion to evasive rather that straight
		expand:

			expand the slot with evasive or straight surfaces to ease itnersection with other meshes

			- `True` enables expansion with a default length
			- `float` set the expansion distance
	'''
	rext = dext/2
	tol = stceil(rext*1e-2)
	profile = [
		rext*X + 0.5*height*Z,
		rext*X - 0.5*height*Z,
		]
	if shouldering:
		profile.insert(0, profile[0] - 0.17*rext*X)
	if circlip:
		circlip_height = stceil(0.1*rext)
		circlip_depth = stceil(1.05*rext) - rext
		profile[-1:] = accumulate([
			rext*X - (0.5*height + tol)*Z,
			circlip_depth*X,
			-circlip_height*Z,
			-circlip_depth*X,
			-0.5*circlip_height*Z,
			])
	if expand == True:	expand = 0.4*rext
	if evade:
		if shouldering:
			profile.insert(0, profile[0] + 0.1*rext*Z)
		profile.append(profile[-1] + expand*(X-Z))
		profile.insert(0, profile[0] + expand*(X+Z))
	elif expand:
		profile.extend([
			profile[-1] - 0.05*rext*(Z-X),
			profile[-1] - 0.05*rext*(Z-X) - expand*Z,
			])
		profile.insert(0, profile[0] + expand*Z)
	return revolution(wire(profile).segmented(), Axis(O,-Z)) .transform(translate(axis[0]) * mat4(quat(Z, axis[1])))

bearing_slot_interior(axis, dint, height, shouldering=True, circlip=False, evade=True, expand=True)

slot for a bearing interior ring, such as returned by bearing()

Parameters:

Name Type Description Default
axis Axis

bearing axis placement

required
dint float

bearing dint parameter

required
height float

bearing h parameter

required
shouldering

generate a shoulder to support the top side of the bearing's interior ring

True
circlip

generate a slot for a circlip to support the bottom side of the bearing's interior ring

False
evade

set expansion to evasive rather that straight

True
expand

expand the slot with evasive or straight surfaces to ease itnersection with other meshes

  • True enables expansion with a default length
  • float set the expansion distance
True
Source code in madcad/standard.py
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
def bearing_slot_interior(axis: Axis, dint: float, height: float, shouldering=True, circlip=False, evade=True, expand=True) -> Mesh:
	''' slot for a bearing interior ring, such as returned by `bearing()`

	Parameters:
		axis:  bearing axis placement
		dint:  bearing `dint` parameter
		height:  bearing `h` parameter
		shouldering:  generate a shoulder to support the top side of the bearing's interior ring
		circlip:  generate a slot for a circlip to support the bottom side of the bearing's interior ring
		evade:  set expansion to evasive rather that straight
		expand:

			expand the slot with evasive or straight surfaces to ease itnersection with other meshes

			- `True` enables expansion with a default length
			- `float` set the expansion distance
	'''
	rint = dint/2
	tol = stceil(rint*2e-2)
	profile = [
		rint*X + 0.5*height*Z,
		rint*X - 0.5*height*Z,
		]
	if shouldering:
		profile.insert(0, profile[0] + 0.36*rint*X)
	if circlip:
		circlip_height = stceil(0.2*rint)
		circlip_depth = rint - stceil(0.8*rint)
		profile[-1:] = accumulate([
			rint*X - (0.5*height + tol)*Z,
			-circlip_depth*X,
			-circlip_height*Z,
			circlip_depth*X,
			-0.5*circlip_height*Z,
			])
	if expand == True:	expand = 0.8*rint
	if evade:
		if shouldering:
			profile.insert(0, profile[0] + 0.1*rint*Z)
		profile.append(profile[-1] - expand*(X+Z))
		profile.insert(0, profile[0] - expand*(X-Z))
	elif expand:
		profile.extend([
			profile[-1] - 0.1*rint*(Z+X),
			profile[-1] - 0.1*rint*(Z+X) - expand*Z,
			])
		profile.insert(0, profile[0] + expand*Z)
	return revolution(wire(profile).segmented(), Axis(O,Z)) .transform(translate(axis[0]) * mat4(quat(Z, axis[1])))

circular_screwing(axis, radius, height, dscrew, diameters=1, div=8, hold=0)

holes and bolts to screw a circular perimeter

Parameters:

Name Type Description Default
axis

placement of circle around which the screws are placed

required
radius

radius of the perimeter on which to put the screws

required
height

bolts length

required
dscrew

diameter of the biggest screws

required
diameters int

each biggest screw is followed by this number-1 of additional smaller diameters

1
div int

number of biggest screws distributed uniformly on the perimeter

8
hold float

if non zero, holding screws of the given length are added to help the assembly. if True, the holding screws length is automatically determined.

0

Return: a tuple (holes:Mesh, bolts:list) where the bolts is a list of Solid

Source code in madcad/standard.py
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
def circular_screwing(axis, radius, height, dscrew, diameters:int=1, div:int=8, hold:float=0) -> '(Mesh, list)':
	''' holes and bolts to screw a circular perimeter

	Parameters:
		axis:  placement of circle around which the screws are placed
		radius: radius of the perimeter on which to put the screws
		height: bolts length
		dscrew: diameter of the biggest screws
		diameters: each biggest screw is followed by this number-1 of additional smaller diameters
		div: number of biggest screws distributed uniformly on the perimeter
		hold:
			if non zero, holding screws of the given length are added to help the assembly.
			if True, the holding screws length is automatically determined.

	Return: a tuple (holes:Mesh, bolts:list) where the bolts is a list of `Solid`
	'''
	holes = Mesh()
	bolts = []
	x,y,z = dirbase(axis.direction)
	a = axis.origin + radius*x
	b = axis.origin + radius*x + height*z
	gap = 0.1*dscrew*z
	enlarge = 1.05
	bolts.append(bolt(a, b, dscrew))
	for i in range(diameters):
		holes += cylinder(a-gap, b+gap, enlarge*stfloor(0.8**i * dscrew)/2) .transform(rotatearound(i*1.4*dscrew/radius, axis))
	holes = repeataround(holes, 8, axis).flip()
	if hold is True:
		hole = 1.5*dscrew
	if hold:
		angle = 1.7*dscrew/radius
		holes += repeataround(screw_slot(Axis(a+gap,-z), dscrew,
					screw=height-hold,
					hole=hold,
					flat=True), 2) .transform(rotatearound(-angle, axis))
		bolts.append(screw(dscrew, height, head='flat')
			.place((Revolute, Axis(O,Z), Axis(a,-z)))
			.transform(rotatearound(-angle, axis)))
		bolts.append(screw(dscrew, height, head='flat')
			.place((Revolute, Axis(O,Z), Axis(a,-z)))
			.transform(rotatearound(pi-angle, axis)))
	return holes, bolts

grooves_profile(radius, repetitions=16, alignment=0.5, angle=radians(40))

Coupling grooves profile

  • The size of grooves depend on the pressure angle and the number of grooves

Parameters:

Name Type Description Default
radius

the radius around which the grooves are placed

required
repetitions int

the number of grooves to put on the circle perimeter

16
alignemnt

fraction of the grooves height - exterior grooves usually have alignment=1 - interior grooves usually have alignemnt=0

required
angle

pressure angle of the grooves

radians(40)
Source code in madcad/standard.py
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
def grooves_profile(radius, repetitions:int=16, alignment=0.5, angle=radians(40)) -> Wire:
	''' Coupling grooves profile

	- The size of grooves depend on the pressure angle and the number of grooves

	Parameters:
		radius: the radius around which the grooves are placed
		repetitions: the number of grooves to put on the circle perimeter
		alignemnt: fraction of the grooves height
			- exterior grooves usually have alignment=1
			- interior grooves usually have alignemnt=0
		angle: pressure angle of the grooves
	'''
	h = radius/repetitions / tan(angle)
	def profile(t, min=-1, max=1):
		return (radius+(0.5-alignment)*h+h*sin(repetitions*t)) * vec3(cos(t), sin(t), 0)
	return wire([ profile(t, -1, 0.7)
		for t in linrange(0, 2*pi, div=12*repetitions, end=False) ]).close()

grooves(radius, height, repetitions=16, alignment=0.5, angle=radians(40))

Coupling grooves surface

  • The bottom and top bevels direction depend on the alignment
  • The size of grooves depend on the pressure angle and the number of grooves

Parameters:

Name Type Description Default
radius

the radius around which the grooves are placed

required
height

the length of the grooves, including transition bevels

required
repetitions int

the number of grooves to put on the circle perimeter

16
alignemnt

fraction of the grooves height - exterior grooves usually have alignment=1 - interior grooves usually have alignemnt=0

required
angle

pressure angle of the grooves

radians(40)
Source code in madcad/standard.py
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
def grooves(radius, height, repetitions:int=16, alignment=0.5, angle=radians(40)) -> Mesh:
	''' Coupling grooves surface

	- The bottom and top bevels direction depend on the alignment
	- The size of grooves depend on the pressure angle and the number of grooves

	Parameters:
		radius: the radius around which the grooves are placed
		height: the length of the grooves, including transition bevels
		repetitions: the number of grooves to put on the circle perimeter
		alignemnt: fraction of the grooves height
			- exterior grooves usually have alignment=1
			- interior grooves usually have alignemnt=0
		angle: pressure angle of the grooves
	'''
	h = radius/repetitions / tan(angle)
	if alignment > 0.5:    s = 1+h/radius
	else:                  s = 1-h/radius
	return extrans(grooves_profile(radius, repetitions, alignment, angle), [
				scale(vec3(s)),
				translate(h*Z),
				translate((height-h)*Z),
				translate(height*Z) * scale(vec3(s)),
				])

Kinematics

scara(backarm, forearm)

kinematic of a classical scara robot arm

scara

Source code in madcad/standard.py
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
def scara(backarm:float, forearm:float) -> Kinematic:
	'''
	kinematic of a classical *scara* robot arm

	![scara](../screenshots/standard-scara.png)
	'''
	return Chain([
		Revolute(('base',1), Axis(O,Z)),
		Revolute((1,2), Axis(backarm*X,Z), Axis(O,Z)),
		Revolute((2,3), Axis(forearm*X,Z), Axis(O,Z)),
		Prismatic((3,'tool'), Axis(-forearm*0.5*Z,Z)),
		])

serial6(backarm, forearm)

kinematic of a classical serial robot arm with 6 degrees of freedom

serial6

Parameters:

Name Type Description Default
backarm float

backarm length

required
forearm float

forearm length

required
Source code in madcad/standard.py
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
def serial6(backarm:float, forearm:float) -> Kinematic:
	'''
	kinematic of a classical serial robot arm with 6 degrees of freedom

	![serial6](../screenshots/standard-serial6.png)

	Parameters:
		backarm:  backarm length
		forearm:  forearm length
	'''
	return Chain([
		Revolute(('base',1), Axis(-0.3*backarm*Z,Z)),  # shoulder 1
		Revolute((1,2), Axis(O,Y)),  # shoulder 2
		Revolute((2,3), Axis(backarm*Z,Y), Axis(O,Y)), # elbow
		Revolute((3,4), Axis(0.5*forearm*Z,Z)),  # wrist 1
		Revolute((4,5), Axis(forearm*Z,Y), Axis(O,Y)), # wrist 2
		Revolute((5,'tool'), Axis(0.3*forearm*Z,Z)), # wrist 3
		])

serial7(backarm, forearm)

kinematic of a classical serial robot arm with 7 degrees of freedom

serial7

Parameters:

Name Type Description Default
backarm float

backarm length

required
forearm float

forearm length

required
Source code in madcad/standard.py
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
def serial7(backarm:float, forearm:float) -> Kinematic:
	'''
	kinematic of a classical serial robot arm with 7 degrees of freedom

	![serial7](../screenshots/standard-serial7.png)

	Parameters:
		backarm:  backarm length
		forearm:  forearm length
	'''
	return Chain([
		Revolute(('base',1), Axis(-0.3*backarm*Z,Z)),  # shoulder 1
		Revolute((1,2), Axis(O,Y)),  # shoulder 2
		Revolute((2,3), Axis(0.5*backarm*Z,Z)),  # 7th degree
		Revolute((3,4), Axis(backarm*Z,Y), Axis(O,Y)), # elbow
		Revolute((4,5), Axis(0.5*forearm*Z,Z)),  # wrist 1
		Revolute((5,6), Axis(forearm*Z,Y), Axis(O,Y)), # wrist 2
		Revolute((6,'tool'), Axis(0.3*forearm*Z,Z)), # wrist 3
		])

delta3(base, tool, backarm, forearm, forearm_width=None)

kinematic of a classical delta robot with 3 degrees of freedom

delta3

Parameters:

Name Type Description Default
base float

the radius of motors placements

required
tool float

the radius of the tool's ball joints placements

required
backarm float

backarm length

required
forearm float

forearm length

required
forearm_width float

gap between the 2 forarm segments

None
Source code in madcad/standard.py
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
def delta3(base:float, tool:float, backarm:float, forearm:float, forearm_width:float=None) -> Kinematic:
	'''
	kinematic of a classical delta robot with 3 degrees of freedom

	![delta3](../screenshots/standard-delta3.png)

	Parameters:
		base:   the radius of motors placements
		tool:   the radius of the tool's ball joints placements
		backarm:  backarm length
		forearm:  forearm length
		forearm_width:  gap between the 2 forarm segments
	'''
	if forearm_width is None:	forearm_width = 0.1*forearm
	from . import generation as gt
	arms = gt.regon(Axis(O,Z), 1, 3).points
	motors = []
	joints = []
	for i, p in enumerate(arms):
		motors.append(Revolute(('base', f'backarm.{i}'), Axis(p,cross(Z, p*base)), Axis(O,X)))
		joints.append(Ball((f'backarm.{i}', f'forearm.{i}.0'), backarm*Z + forearm_width*X, O))
		joints.append(Ball((f'backarm.{i}', f'forearm.{i}.1'), backarm*Z - forearm_width*X, O))
		joints.append(Ball(('tool', f'forearm.{i}.0'), p*tool + forearm_width*cross(Z,p), forearm*Z))
		joints.append(Ball(('tool', f'forearm.{i}.1'), p*tool - forearm_width*cross(Z,p), forearm*Z))

	kin = Kinematic(joints, inputs=motors, outputs=['tool'], ground='base')
	kin.default = kin.solve({kin.outputs[0]: kin.outputs[0].inverse(translate(-forearm*Z))}, maxiter=1000)
	return kin