Generation
The functions here generare meshes from simpler objects (like lower dimension meshes, or simple primitives). You won't find here iterative methods, nor adaptative geometry operations, nor mesh modification operations. The functions here may eventually be complex but will always feel predictable and simple from a human perspective.
Based on extrusion/transformation of a Web¶
extrans(section, transformations, links=None)
¶
Create a surface by extruding and transforming the given outline.

Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
a |
required | |
transformations
|
iter
|
iterable of mat4, one each section |
required |
links
|
iterable of tuples (a,b,t) with
If |
None
|
Examples:
>>> extrans(
... regon(Axis(O,Z), 1, 4),
... [translate(t*Z) * scale(vec3(0.5+t**2)) for t in linrange(-1, 1, div=10)],
... )
Source code in madcad/generation.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
extrusion(shape, trans, alignment=0)
¶
Create a surface by extruding the given outline by a transformation

Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
a line (Web or Wire) or a surface (Mesh) to extrude |
required | |
trans
|
any transformation object accepted by |
required | |
alignment
|
float
|
the relative position of the input shape in the resulting mesh
- |
0
|
Examples:
>>> extrusion(ArcThrough(+Y, Z, -Y), 2*X)
Source code in madcad/generation.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
revolution(shape, axis=Axis(O, Z), angle=2 * pi, alignment=0, resolution=None)
¶
Create a revolution surface by extruding the given outline
steps is the number of steps between the start and the end of the extrusion

Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
the shape to extrude (Web, Wire, or Mesh), ideally a section |
required | |
angle
|
float
|
angle of rotation between the given profile and the final produced profile |
2 * pi
|
axis
|
the axis to rotate around |
Axis(O, Z)
|
|
alignment
|
float
|
the relative position of the input shape in the resulting mesh
|
0
|
resolution
|
resolution setting for the biggest produced circle, such as for primitives |
None
|
Examples:
>>> revolution(
... ArcThrough(4*Z+Y, 6*Z, 4*Z-Y),
... Axis(O,Y),
... 1.5*pi,
... )
Source code in madcad/generation.py
57 58 59 60 61 62 63 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 91 92 93 94 95 | |
helix(shape, height, angle, radius=1.0, axis=Axis(O, Z), alignment=0.0, resolution=None)
¶
Extrude the given shape by rotating and translating along an axis

This variant expects the input shape to be close to orthogonal to the axis direction and is used to produce an screw/helix from its section
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
the shape to extrude (Web, Wire, or Mesh), ideally a section |
required | |
height
|
float
|
the maximum translation in the |
required |
radius
|
float
|
the radius at which the hexlix |
1.0
|
angle
|
float
|
the helix angle at |
required |
axis
|
the axis to rotate around and translate along |
Axis(O, Z)
|
|
alignment
|
float
|
the relative position of the input shape in the resulting mesh
|
0.0
|
resolution
|
resolution setting for subdivisions |
None
|
Examples:
>>> helix(
... regon(Axis(O,Z), 1, 4).subdivide(4),
... height=2,
... angle=radians(45),
... )
Source code in madcad/generation.py
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 | |
screw(shape, turns=1.0, axis=Axis(O, Z), step=None, alignment=0.0, resolution=None)
¶
Extrude the given shape by rotating and translating along an axis

This variant expects the input shape to be close to coplanar to the axis direction and is used to produce a screw/helix from its profile
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
the shape to extrude (Web, Wire, or Mesh), ideally a profile |
required | |
turns
|
float
|
number of complete rotations of the profile |
1.0
|
step
|
float
|
the translation after a complete rotation, if not provided it is automatically adjusted to the profile's height |
None
|
axis
|
the axis to rotate around and translate along |
Axis(O, Z)
|
|
alignment
|
float
|
the relative position of the input shape in the resulting mesh
|
0.0
|
resolution
|
resolution setting for subdivisions |
None
|
Examples:
>>> screw(
... wire([vec3(0,1,1), vec3(0,2,1), vec3(0,1,0)]).segmented(),
... turns=2,
... )
Source code in madcad/generation.py
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 | |
saddle(a, b)
¶
Create a surface by extruding outine1 translating each instance to the next point of outline2

Examples:
>>> saddle(
... ArcThrough(+Y,X,-Y),
... Softened([0*X, 0*X-2*Z, 4*X-2*Z, 4*X]),
... )
Source code in madcad/generation.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
tube(shape, path, end=True, section=True)
¶
Create a tube surface by extruding the shape along the path if section is True, there is a correction of the segments to keep the section rigid by the curve

Examples:
>>> tube(
... ArcThrough(+Y,X,-Y),
... Softened([0*X, 0*X-2*Z, 4*X-2*Z, 4*X]),
... )
Source code in madcad/generation.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
Generation of common meshes¶
regon(axis, radius, n, alignment=vec3(1, 0, 0))
¶
Create a regular n-gon Wire, the same way we create a Circle

Source code in madcad/generation.py
676 677 678 679 680 681 682 683 684 685 | |
square(axis, width)
¶
Return a simple square with the given normal axis and square width.

Useful to quickly create a cutplane
Source code in madcad/generation.py
599 600 601 602 603 604 605 606 607 608 609 610 611 | |
brick(*args, **kwargs)
¶
A simple brick with rectangular axis-aligned sides

It can be constructed in the following ways:
brick(Box)brick(min, max)brick(center=vec3(0), size=vec3(-inf), alignment=0.5)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
the corner with minimal coordinates |
required | |
max
|
the corner with maximal coordinates |
required | |
center
|
the center of the box |
required | |
size
|
the all positive diagonal of the box |
required | |
alignment
|
where the center is inside the box |
required |
Source code in madcad/generation.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 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 | |
parallelogram(*directions, origin=vec3(0), alignment=vec3(0), fill=True)
¶
Create a parallelogram or parallelepiped depending on the number of directions given

Parameters:
directions: list of 1-3 directions, they must for a right handed base for the face normals to be oriented outward
origin: origin the resulting shape, the shape will placed relatively to that point
alignment: relative position of the origin in the shape: 0 means at start of each direction, 1 means at the tip of each direction
fill:
- if True, a mesh will be generated (forming a surface with 2 directions, or an envelope with 3 directions)
- if False, a Web will be generated
Source code in madcad/generation.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
cylinder(bottom, top, radius, fill=True, resolution=None)
¶
Create a revolution cylinder, with the given radius

Parameters:
bottom, top (vec3): the cylinder extremities centers
fill (bool): whether to put faces at both extremities
Source code in madcad/generation.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
cone(summit, base, radius, fill=True, resolution=None)
¶
Create a revolution cone, with a base of the given radius

Parameters:
summit (vec3): The point at the top of the cone
base (vec3): the center point of the base
fill (bool): whether to put a face at the base
Source code in madcad/generation.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
pyramid(summit, base)
¶
Create a pyramid with the given summit point and the given base

Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summit
|
vec3
|
the top (summit) of the cone, not necessarity in the center of the shape |
required |
base
|
(Mesh,Web,Wire): the base shape |
required |
Source code in madcad/generation.py
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 | |
icosahedron(center, radius)
¶
A simple icosahedron (see https://en.wikipedia.org/wiki/Icosahedron)

Source code in madcad/generation.py
613 614 615 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 | |
icosphere(center, radius, resolution=None)
¶
A simple icosphere with an arbitrary resolution (see https://en.wikipedia.org/wiki/Geodesic_polyhedron).

Points are obtained from a subdivided icosahedron and reprojected on the desired radius.
Source code in madcad/generation.py
646 647 648 649 650 651 652 653 654 655 656 657 | |
uvsphere(center, radius, alignment=vec3(0, 0, 1), resolution=None)
¶
A simple uvsphere (simple sphere obtained with a revolution of an arc)

Source code in madcad/generation.py
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
Repeating¶
repeat(pattern, repetitions, transform)
¶
Create a mesh duplicating n times the given pattern, each time applying the given transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
can either be a |
required | |
repetitions
|
int
|
the number of repetitions |
required |
transform
|
is the transformation between each duplicate |
required |
Source code in madcad/generation.py
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
repeataround(pattern, repetitions=None, axis=Axis(O, Z), angle=2 * pi)
¶
same as [repeat] using [rotatearound]
Source code in madcad/generation.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | |
Others¶
fill(outline, normal=None)
¶
Generates a surface for a flat outline using the prefered triangulation method.

If normal is specified, it must be the normal vector to the plane, and will be used to orient the face.
Source code in madcad/generation.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
icosurface(pts, ptangents, resolution=None)
¶
Generate a surface ICO (a subdivided triangle) with its points interpolated using interpol2tri.
- If normals are given instead of point tangents (for ptangents), the surface will fit a sphere.
- Else
ptangentsmust be a list of couples (2 edge tangents each point).
Source code in madcad/generation.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |