primitives -- 3D Primitives for Wire generation¶
Definition of 3D primitive objects
Primitives are parameterized objects, that can be baked into a mesh/web/wire object. A primitive object must have the following signature:
class SomePrimitive:
# method baking the primitive in some general-purpose 3D object
def mesh(self) -> Mesh/Web/Wire:
...
# for the solver
# primitive attributes the solver has to consider as variables or variable container
slvvars = 'fields', 'for', 'solver', 'variables'
# optional method constraining the primitive parameters (to keep points on a circle for instance)
def fit(self) -> err**2 as float:
...
Curve resolution¶
Some primitive types are curves, the discretisation is important for visual as well as for result quality (remember that even if something looks like a perfect curves, it's still polygons). The resolution (subdivision) of curve is done following the following cirterions present in the 'settings' module
Specification priority order:
- Optional argument
resolutionpassed toprimitive.mesh()or toweb()orwire() - Optional attribute
resolutionof the primitive object - Value of
settings.resolutionat bake time.
Specification format:
('fixed', 16) # fixed amount of 16 subdivisions
('rad', 0.6) # max polygon angle is 0.6 rad
('radm', 0.6)
('radm2', 0.6)
Primitives are parametrized objects, that can be baked into a mesh/web/wire object. A primitive object must have the following signature:
class SomePrimitive:
# method baking the primitive in some general-purpose 3D object
# resolution is optional and defaults to the primitive settings
# that defaults to the current settings at call time
def mesh(self, resolution=None) -> Mesh/Web/Wire:
...
# for the solver
# primitive attributes the solver has to consider as variables or variable container
slvvars = 'fields', 'for', 'solver', 'variables'
# optional method constraining the primitive parameters (to keep points on a circle for instance)
def fit(self) -> err**2 as float:
...
isprimitive(obj)
¶
Return True if obj match the signature for primitives
Source code in madcad/primitives.py
60 61 62 | |
Curve resolution¶
Some primitive types are curves, the discretization is important for visual as well as for result quality (remember that even if something looks like a perfect curves, it's still polygons). The resolution (subdivision) of curve is done following the following criterion present in the settings module
Specification priority order:
- Optional argument
resolutionpassed toprimitive.mesh()or toweb()orwire() - Optional attribute
resolutionof the primitive object - Value of
settings.resolutionat bake time.
Specification format:
('fixed', 16) # fixed amount of 16 subdivisions
('rad', 0.6) # max polygon angle is 0.6 rad
('radm', 0.6)
('radm2', 0.6)
Primitives types¶
Segment(a, b)
¶
Bases: object
Segment from a to b

Source code in madcad/primitives.py
75 76 | |
__slots__ = ('a', 'b')
class-attribute
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
direction
property
¶
origin
property
¶
slvvars = ('a', 'b')
class-attribute
instance-attribute
¶
__call__(t)
¶
Source code in madcad/primitives.py
80 81 | |
slv_tangent(pt)
¶
Source code in madcad/primitives.py
92 93 | |
mesh(resolution=None)
¶
Source code in madcad/primitives.py
95 96 | |
__repr__()
¶
Source code in madcad/primitives.py
98 99 | |
display(scene)
¶
Source code in madcad/primitives.py
101 102 | |
Circle(axis, radius, alignment=vec3(1, 0, 0), resolution=None)
¶
Bases: object
Circle centered around the axis origin, with the given radius, in an orthogonal plane to the axis direction

Source code in madcad/primitives.py
322 323 324 325 | |
__slots__ = ('axis', 'radius', 'alignment', 'resolution')
class-attribute
instance-attribute
¶
alignment = alignment
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
center
property
¶
slvvars = ('axis', 'radius')
class-attribute
instance-attribute
¶
slv_tangent = tangent
class-attribute
instance-attribute
¶
fit()
¶
Source code in madcad/primitives.py
333 334 | |
tangent(pt)
¶
Tangent to the closest point of the curve to pt
Source code in madcad/primitives.py
336 337 338 | |
mesh(resolution=None)
¶
Source code in madcad/primitives.py
343 344 345 346 347 348 349 350 | |
__repr__()
¶
Source code in madcad/primitives.py
352 353 | |
display(scene)
¶
Source code in madcad/primitives.py
355 356 | |
ArcCentered(axis, a, b, resolution=None)
¶
Bases: object
Arc from a to b, centered around the origin of the axis.

An axis is requested instead of a point (that would be more intuitive), to solve the problem when a,b, center are aligned
Source code in madcad/primitives.py
161 162 163 164 | |
__slots__ = ('axis', 'a', 'b', 'resolution')
class-attribute
instance-attribute
¶
axis = axis
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
center
property
¶
radius
property
¶
slvvars = ('axis', 'a', 'b')
class-attribute
instance-attribute
¶
slv_tangent = tangent
class-attribute
instance-attribute
¶
tangent(pt)
¶
Tangent to the closest point of the curve to pt
Source code in madcad/primitives.py
176 177 178 | |
fit()
¶
Source code in madcad/primitives.py
182 183 184 185 186 187 | |
mesh(resolution=None)
¶
Source code in madcad/primitives.py
189 190 | |
__repr__()
¶
Source code in madcad/primitives.py
192 193 | |
display(scene)
¶
Source code in madcad/primitives.py
195 196 | |
ArcThrough(a, b, c, resolution=None)
¶
Bases: object
Arc from a to c, passing through b

Source code in madcad/primitives.py
111 112 113 | |
__slots__ = ('a', 'b', 'c', 'resolution')
class-attribute
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
center
property
¶
radius
property
¶
axis
property
¶
slvvars = ('a', 'b', 'c')
class-attribute
instance-attribute
¶
slv_tangent = tangent
class-attribute
instance-attribute
¶
tangent(pt)
¶
Tangent to the closest point of the curve to pt
Source code in madcad/primitives.py
134 135 136 137 | |
mesh(resolution=None)
¶
Source code in madcad/primitives.py
142 143 144 145 | |
__repr__()
¶
Source code in madcad/primitives.py
147 148 | |
display(scene)
¶
Source code in madcad/primitives.py
150 151 | |
ArcTangent(a, b, c, resolution=None)
¶
Bases: object
An arc always tangent to Segment(a,b) and Segment(c,b). The solution is unique.

Source code in madcad/primitives.py
204 205 206 | |
__slots = ('a', 'b', 'c')
class-attribute
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
center
property
¶
radius
property
¶
axis
property
¶
slvvars = ('a', 'b', 'c')
class-attribute
instance-attribute
¶
slv_tangent = tangent
class-attribute
instance-attribute
¶
tangent(pt)
¶
Tangent to the closest point of the curve to pt
Source code in madcad/primitives.py
226 227 228 229 | |
fit()
¶
Source code in madcad/primitives.py
234 235 | |
mesh(resolution=None)
¶
Source code in madcad/primitives.py
237 238 | |
__repr__()
¶
Source code in madcad/primitives.py
240 241 | |
display(scene)
¶
Source code in madcad/primitives.py
243 244 | |
Ellipsis(center, minor, major, resolution=None)
¶
Bases: object
Ellipsis centered around the given point, with the given major and minor semi axis
Source code in madcad/primitives.py
361 362 363 364 365 | |
__slots__ = ('center', 'minor', 'major', 'resolution')
class-attribute
instance-attribute
¶
center = center
instance-attribute
¶
minor = minor
instance-attribute
¶
major = major
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
axis
property
¶
the ellipsis axis, deduces from its major and minor semi axis
slvvars = ('center', 'minor', 'major')
class-attribute
instance-attribute
¶
mesh(resolution=None)
¶
Source code in madcad/primitives.py
376 377 378 379 380 381 382 383 | |
__repr__()
¶
Source code in madcad/primitives.py
385 386 | |
display(scene)
¶
Source code in madcad/primitives.py
388 389 | |
TangentEllipsis(a, b, c, resolution=None)
¶
Bases: object
An quater of ellipsis always tangent to Segment(a,b) and Segment(c,b). The solution is unique.

Source code in madcad/primitives.py
268 269 270 | |
__slots__ = ('a', 'b', 'c', 'resolution')
class-attribute
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
axis
property
¶
center
property
¶
slvvars = ('a', 'b', 'c')
class-attribute
instance-attribute
¶
slv_tangent = tangent
class-attribute
instance-attribute
¶
__call__(t)
¶
Source code in madcad/primitives.py
274 275 276 277 278 279 | |
tangent(pt)
¶
Tangent to the closest point of the curve to pt
Source code in madcad/primitives.py
289 290 291 292 | |
mesh(resolution=None)
¶
Axis directions doesn't need to be normalized nor oriented
Source code in madcad/primitives.py
297 298 299 300 301 302 303 304 305 306 307 308 | |
__repr__()
¶
Source code in madcad/primitives.py
310 311 | |
display(scene)
¶
Source code in madcad/primitives.py
313 314 | |
Interpolated(points, weights=None, resolution=None)
¶
Bases: object
Interpolated curve passing through the given points (3rd degree bezier spline)

The tangent in each point is determined by the direction between adjacent points The point weights is how flattened is the curve close to the point tangents
Source code in madcad/primitives.py
408 409 410 411 | |
__slots__ = ('points', 'weights', 'resolution')
class-attribute
instance-attribute
¶
points = points
instance-attribute
¶
weights = weights or [1] * len(self.points)
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
mesh(resolution=None)
¶
Source code in madcad/primitives.py
415 416 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 | |
box()
¶
Source code in madcad/primitives.py
447 448 | |
__repr__()
¶
Source code in madcad/primitives.py
450 451 | |
display(scene)
¶
Source code in madcad/primitives.py
453 454 455 | |
Softened(points, weights=None, resolution=None)
¶
Bases: object
Interpolated curve tangent to each segment midpoint (3rd degree bezier curve)

The points weights is the weight in the determination of each midpoint
Source code in madcad/primitives.py
465 466 467 468 | |
__slots__ = ('points', 'weights', 'resolution')
class-attribute
instance-attribute
¶
points = points
instance-attribute
¶
weights = weights or [1] * len(self.points)
instance-attribute
¶
resolution = resolution
instance-attribute
¶
__eq__ = _trivial_eq
class-attribute
instance-attribute
¶
mesh(resolution=None)
¶
Source code in madcad/primitives.py
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 | |
box()
¶
Source code in madcad/primitives.py
501 502 | |
__repr__()
¶
Source code in madcad/primitives.py
504 505 | |
display(scene)
¶
Source code in madcad/primitives.py
507 508 509 | |