constraints -- Geometric constraints on primitives¶
This modules defines the constraints definitions and the solver tools
Constraints can be any object referencing variables and implementing the following signature to guide the solver in the resolution:
class SomeConstraint:
# name the attributes referencing the solver variables to change
slvvars = 'some_primitive', 'some_point'
# function returning the squared error in the constraint
# for a coincident constraint for instance it's the squared distance
# the error must be a contiguous function of the parameters, and it's squared for numeric stability reasons.
# the solver internally use an iterative approach to optimize the sum of all fit functions.
def fit((self):
...
This modules defines the constraints definitions and the solver tools
Constraints can be any object referencing variables and implementing the following signature to guide the solver in the resolution:
class SomeConstraint:
# name the attributes referencing the solver variables to change
slvvars = 'some_primitive', 'some_point'
# function returning the squared error in the constraint
# for a coincident constraint for instance it's the squared distance
# the error must be a contiguous function of the parameters, and it's squared for numeric stability reasons.
# the solver internally use an iterative approach to optimize the sum of all fit functions.
def fit(self):
...
isconstraint(obj)
¶
Return True if obj match the constraint signature
Source code in madcad/constraints.py
48 49 50 | |
Solver¶
solve(constraints, fixed=(), *args, **kwargs)
¶
Short hand to use the class Problem
Source code in madcad/constraints.py
196 197 198 | |
Problem(constraints, fixed=())
¶
Class to holds data for a problem solving process. it is intended to be instantiated for each different probleme solving, an instance is used multiple times only when we want to solve on top of the previous results, using exactly the same probleme definition (constraints and variables)
Therefore the solver protocol is the following
- constraints define the problem
-
each constraint refers to variables it applies on constraints have the method fit() and a member 'slvvars' that can be
1. An iterable of names of variable members in the constraint object 2. A function returning an iterable of the actual variables objects (that therefore must be referenced refs and not primitive types) -
each variable object can redirect to other variable objects if they implements such a member 'slvvars'
- primitives can also be constraints on their variables, thus they must have a method fit() (but no member 'primitives' here)
- primitives can implement the optional solver methods for some constraints, such as 'slv_tangent'
Source code in madcad/constraints.py
216 217 218 219 220 221 222 223 224 225 226 227 228 | |
constraints = set()
instance-attribute
¶
slvvars = {}
instance-attribute
¶
dim = 0
instance-attribute
¶
register(obj)
¶
Register a constraint or a variable object
Source code in madcad/constraints.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
unregister(obj)
¶
Unregister all variables from a constraint or a variable object
Source code in madcad/constraints.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
state()
¶
Source code in madcad/constraints.py
273 274 275 276 277 278 279 280 | |
place(x)
¶
Source code in madcad/constraints.py
282 283 284 285 286 287 | |
fit()
¶
Source code in madcad/constraints.py
289 290 291 292 293 | |
evaluate(x)
¶
Source code in madcad/constraints.py
295 296 297 | |
solve(precision=1e-06, method='trf', maxiter=None, afterset=None)
¶
Source code in madcad/constraints.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
Constraints definitions¶
Distance(*args, **kwargs)
¶
Bases: Constraint
Makes two points distant of the fixed given distance
Source code in madcad/constraints.py
37 38 39 40 41 | |
__slots__ = ('p1', 'p2', 'd', 'along', 'location')
class-attribute
instance-attribute
¶
slvvars = ('p1', 'p2')
class-attribute
instance-attribute
¶
fit()
¶
Source code in madcad/constraints.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
display(scene)
¶
Source code in madcad/constraints.py
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 | |
Radius(*args, **kwargs)
¶
Bases: Constraint
Gets the given Arc with the given fixed radius
Note: Only ArcCentered are supported yet.
Source code in madcad/constraints.py
37 38 39 40 41 | |
__slots__ = ('arc', 'radius', 'location')
class-attribute
instance-attribute
¶
slvvars = ('arc',)
class-attribute
instance-attribute
¶
fit()
¶
Source code in madcad/constraints.py
160 161 | |
display(scene)
¶
Source code in madcad/constraints.py
163 164 165 166 167 168 169 170 171 | |
Angle(*args, **kwargs)
¶
Bases: Constraint
Gets two segments with the given fixed angle between them
Source code in madcad/constraints.py
37 38 39 40 41 | |
__slots__ = ('s1', 's2', 'angle')
class-attribute
instance-attribute
¶
slvvars = ('s1', 's2')
class-attribute
instance-attribute
¶
fit()
¶
Source code in madcad/constraints.py
130 131 132 133 134 | |
display(scene)
¶
Source code in madcad/constraints.py
136 137 138 139 140 141 | |
Tangent(*args, **kwargs)
¶
Bases: Constraint
Makes to curves tangent in the given point The point moves as well as curves.
The curves primitives must have a member slv_tangent(p) returning the tangent vector at the nearest position to p
Source code in madcad/constraints.py
37 38 39 40 41 | |
OnPlane(*args, **kwargs)
¶
Bases: Constraint
Puts the given points on the fixed plane given by its normal axis
Source code in madcad/constraints.py
37 38 39 40 41 | |