Constraints are conditions that shapes must satisfy when the solver is being called. Consrtaints can be added by the user or automatically, during solving, to preserve the shape’s characteristics.

The constraints that can be added by the user are:

  • fixed point constraints
  • shape specific constraints (e.g. line length)
  • constraints between two shapes (e.g. concentric circles)

The constraints that are added automatically, during solving, are called soft constraints and they’re currently added for line length, arc radius and arc start and end angle.

Calculating constraints

Each constraint has a method where the deviation from the desired value is calculated. The values used for the calculation are stored in a list, which contains double values – the coordinates of the points and the constraints list contains the indexes in the parameters list, instead of actual values.

Let’s say we have two parallel lines, with the node indexes as shown:

The paramaters list will contain the coordinates for nodes 1,2,4 and 5:

parameters content: [ 3.0   6.0   1.0   1.0   8.0   5.0   5.0   0.0 ]
                    [ P1.x  P1.y  P2.x  P2.y  P4.x  P4.y  P5.x  P5.y]
indexes:            [  0     1     2     3     4     5     6     7  ]

The indexes will be used in the constraints list. To define that the line P1P2 is parallel to P4P5 we add a new constraint wich has two lines, defined by the point indexes:

L1 = new Line { P1 = new Point(0,1), P2 = new Point(2,3) }
L2 = new Line { P1 = new Point(4,5), P2 = new Point(6,7) }

Using this structure, whenever the point position changes, the parameters value is changed, but the constraint stays the same and will always use the updated version of the coordinate. If a solutions is found, the coordinates are automatically updated by updating the node, using an additional mapping between the parameters indexes and the shape index.

Point to Point constraint

The Point to Point constraint fixes the distance between two points, regardless of the shapes they are part of.

Point constraints

Line constraints

Circle constraints

Arc constraints

Arc and circle constraints

Soft constraints

Removing constraints

Soft constraints are removed automatically after the Solver was called. If no solution is found when using the soft constraints, they are removed and the solver is called again.

The user added constraints can be removed by selecting the shapes and unchecking the corresponding box. For the shape specific constraints, clicking the lock button again removes the constraint.

Pages
Blogroll





The best Android Market
AndroidPit